Dereference device with a defer call to prevent memory leaks (#98)

We should always dereference devices. c.libusb.open is keeping its own internal reference so there is no risk of breaking anything.
This commit is contained in:
danielpaulus
2021-11-01 21:40:49 +01:00
committed by GitHub
parent 0eba1b1264
commit 0ce3a07f8e
2 changed files with 15 additions and 16 deletions

View File

@@ -209,7 +209,7 @@ func (libusbImpl) getDevices(ctx *libusbContext) ([]*libusbDevice, error) {
for _, d := range devs {
ret = append(ret, (*libusbDevice)(d))
}
// devices will be dereferenced later, during close.
// devices must be dereferenced by the caller to prevent memoryleaks
C.libusb_free_device_list(list, 0)
return ret, nil
}