Skip to content

Commit 8c5522f

Browse files
Merge pull request #109 from memoos/master
Do not leave socket open in case no device can be found
2 parents 5dde9f6 + 6f64bf4 commit 8c5522f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

linux/hci/socket/socket.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func NewSocket(id int) (*Socket, error) {
7474

7575
req := devListRequest{devNum: hciMaxDevices}
7676
if err = ioctl(uintptr(fd), hciGetDeviceList, uintptr(unsafe.Pointer(&req))); err != nil {
77+
unix.Close(fd)
7778
return nil, errors.Wrap(err, "can't get device list")
7879
}
7980
var msg string
@@ -84,6 +85,7 @@ func NewSocket(id int) (*Socket, error) {
8485
}
8586
msg = msg + fmt.Sprintf("(hci%d: %s)", id, err)
8687
}
88+
unix.Close(fd)
8789
return nil, errors.Errorf("no devices available: %s", msg)
8890
}
8991

0 commit comments

Comments
 (0)