all: fix resource leaks with missing .Close() calls

Fixes #5706

Signed-off-by: Emmanuel T Odeke <emmanuel@orijtech.com>
This commit is contained in:
Emmanuel T Odeke
2022-09-20 21:27:47 -07:00
committed by Brad Fitzpatrick
parent 9bdf0cd8cd
commit f981b1d9da
5 changed files with 21 additions and 3 deletions

View File

@@ -24,11 +24,17 @@ func New(socket string) (*BIRDClient, error) {
return newWithTimeout(socket, responseTimeout)
}
func newWithTimeout(socket string, timeout time.Duration) (*BIRDClient, error) {
func newWithTimeout(socket string, timeout time.Duration) (_ *BIRDClient, err error) {
conn, err := net.Dial("unix", socket)
if err != nil {
return nil, fmt.Errorf("failed to connect to BIRD: %w", err)
}
defer func() {
if err != nil {
conn.Close()
}
}()
b := &BIRDClient{
socket: socket,
conn: conn,