0

I'm working on a basic libusb Visual C++ application in vs2013, which has a Class that calls libusb_get_device_list(ctx, devices) 3 times; once in the constructor, and twice in two functions for printing devices and device descriptions. Each time I call libusb_free_device_list(devices, 1) to release the devices. In the Destructor, I call

libusb_close(deviceHandle);
libusb_exit(ctx);

Nothing breaks, but the libusb_exit(ctx) spits out the warning: libusb: warning [libusb_exit] some libusb_devices were leaked

If I only call libusb_get_device_list(ctx, devices) once, the warning doesn't show.

Has anyone had the same issue and found a way to resolve it?

NOTE:

Whether I use the same instance of libusb_device** or three unique ones, the problem persists

Frederik Petersen
  • 1,025
  • 3
  • 16
  • 30

1 Answers1

0

Update:

This solution does not seem to work every time. For some reason it makes the program throw exceptions sometimes, which I did see the first couple of times I was testing it.

Original Response:

I managed to resolve it myself. It seemed that if I get device list and free it again in constructor. I can still use the freed libusb_device** instance to print the connected devices without creating a new instance or freeing it again.

If anyone one can explain why this is to me, it would still be greatly appreciated as I do not understand why my work around is working and why other setups don't work.

Frederik Petersen
  • 1,025
  • 3
  • 16
  • 30