-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libusb-compat-0.1 devices still referenced upon exit #988
Comments
The following is okay.
Debug log: Click for debug log
|
For the release version of libusb-1.0.21, 1.0.22, 1.0.23 and 1.0.24, the warning message is like the following.
|
Looks like there is a bug in libusb Windows backend. |
This is still there. Probably this is a bug of libusb-compat. Here is the debug log under my Mac Mini M1 running macOS 12.3.
|
Same under Linux (Ubuntu Linux 20.04 x64 version). click for debug log
|
I have closed #974 as it seems to be okay. So I tend to think there is an issue with libusb-compat-0.1 or at least its usage of libusb-1.0 APIs. |
Same under my WIndows 11 machine. click for debug log
|
Just want to mention that the issue is still present with latest version of libusb git HEAD and libusb-compat-0.1. |
Does libusb-compat-0.1 use libusb_free_device_list() with unref_devices = true? I guess it references all devices by running libusb_get_device_list() and then it must unref them all before calling libusb_exit(). |
Yes libusb-compat-0.1 uses Code here: I do not see anything obviously wrong myself. The only thing I am thinking of is to do more clean up in |
The following simple addition to libusb debug log seems to help a bit. We can see device reference count is not zero in the end.
You can refer to the following debug log, under Windows. click for debug log
|
As a comparison, the debug log for libusb's listdevs exmple is here (for Windows). We can see the device reference count is zero in the end. But the cleanup is towards the end. click for debug log
|
@tormodvolden and @hjelmn Is this because libusb-compat-0.1 only does the clean up when libusb-1.0 dynamic library is unloaded as there is no |
Debug log for libusb-compat-0.1 Again we can see there is no issue for libusb click for debug log
Comparison with the debug log for libusb-1.0 click for the debug log
|
The following patch to libusb-compat-0.1 seems to fix the issue. My thought is that libusb will handle the device ref and unref so there should not be handling required by libusb-compat-0.1. But I am not so sure if this is the right fix. I have only tested under Linux as of now. But the code has been there since the initial commit of libusb-compat-0.1 back one May 4, 2008.
Debug log under Linux for reference. We can see now the bahavior of libusb-compat-0.1 is similar to libusb. click for the debug log
|
Same for macOS, once I have the patched version of libusb-compat-0.1, it seems to work as expected. I have also tested libusb-compat-0.1 Modified version of libusb (just to add the debug print for the reference count) and modified version of libusb-compat-0.1 are installed to click for debug log under macOS
|
From here:
#974
Even the example lsusb.c and testlibusb.c are having the same behavior. I am not so sure if this is an issue with libusb-1.0 Windows or libusb-compat-0.1 codes.
Super simple test application (subset of lsusb.c)
Debug log:
Click for debug log
The text was updated successfully, but these errors were encountered: