Closed danielpaulus closed 3 years ago
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
:memo: Please visit https://cla.developers.google.com/ to sign.
Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!
and we'll verify it.
ℹ️ Googlers: Go here for more info.
@googlebot I signed it!
could you also update a comment in https://github.com/google/gousb/blob/master/libusb.go#L212? it is misleading now as it is, since it implies that all devices returned on the list will be "closed" (and so also opened) at some point, but this is not the case.
Done. Should I also create a small unit test for OpenDevices while I am at it?
hey @zagrodzki , is there anything missing on the PR? If not, when do you think you can release it? I would like to move away from using my private fork :-)
sorry, I assumed you will be able to merge yourself after my approval, but it seems this is not how GitHub flow works...
There is one comment left: typo in libusb.go (https://github.com/google/gousb/pull/98#discussion_r621199462)
This PR fixes the memory leak mentioned in #97
gousb.OpenDevices
currently only dereferences libusb device pointers when opening is unsuccessful or when the opener returns false. This can cause a memory leak that becomes mostly visible when using multiple libusb contexts in a long running application.The fix is to always call
c.libusb.dereference(dev)
so the device reference counter is decreased when OpenDevices is done. That is not a problem as libusb increases the reference counter internally on thec.libusb.open(dev)
call and releases it when we callc.libusb.close(dev)
again.