From 6f64bf4d8253bbe94ce4f7958522b45eade3132f Mon Sep 17 00:00:00 2001 From: Melchior Moos Date: Tue, 12 Dec 2023 13:33:30 +0100 Subject: [PATCH] Do not leave socket open in case no device can be found --- linux/hci/socket/socket.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linux/hci/socket/socket.go b/linux/hci/socket/socket.go index 72987390..abe91d02 100644 --- a/linux/hci/socket/socket.go +++ b/linux/hci/socket/socket.go @@ -74,6 +74,7 @@ func NewSocket(id int) (*Socket, error) { req := devListRequest{devNum: hciMaxDevices} if err = ioctl(uintptr(fd), hciGetDeviceList, uintptr(unsafe.Pointer(&req))); err != nil { + unix.Close(fd) return nil, errors.Wrap(err, "can't get device list") } var msg string @@ -84,6 +85,7 @@ func NewSocket(id int) (*Socket, error) { } msg = msg + fmt.Sprintf("(hci%d: %s)", id, err) } + unix.Close(fd) return nil, errors.Errorf("no devices available: %s", msg) }