Windows: Fixes for corner case leaks when reusing device references #64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed my libusb-based program was leaking memory under Windows and tracked it down to leaks that occur when libusb_get_device_list() reuses existing device references.
A test program that demonstrates the problem is here:
https://gist.github.com/projectgus/c9e29f90397202dbba38
The three commits in this PR fix these problems for me.
I've been cross-compiling with mingw and testing on Windows 7 and XP 32-bit. But I don't think those details are relevant.
BTW, thanks very much to everyone who works on libusb. It's marvellous being able to write cross-platform code for something as complex as USB, and have it run everywhere. I am even more admiring of libusb after today, having now become more familiar with the actual Windows USB stack. ;)