airspy / airspyone_host

AirSpy's usemode driver and associated tools
http://airspy.com
245 stars 88 forks source link

Process pending libusb events before shutdown #78

Closed johanhedin closed 3 years ago

johanhedin commented 3 years ago

After libusb_cancel_transfer, pending events need to be handled to avoid memory leaks. See issue #77.

bvernoux commented 3 years ago

After checking your modification proposal mainly using libusb_handle_events_timeout(device->usb_context, &timeout); towards the documentation of libusb https://libusb.sourceforge.io/api-1.0/group__libusb__poll.html#ga6deff4c7d3a6c04bb9ec9fd259b48933

Handle any pending events

Like libusb_handle_events_timeout_completed(), but without the completed parameter, calling this function is equivalent to calling libusb_handle_events_timeout_completed() with a NULL completed parameter.

This function is kept primarily for backwards compatibility. All new code should call libusb_handle_events_completed() or libusb_handle_events_timeout_completed() to avoid race conditions.

You shall change the fix to use recommended API libusb_handle_events_completed() or libusb_handle_events_timeout_completed()

johanhedin commented 3 years ago

Thanks for the feedback. Changed to libusb_handle_events_timeout_completed to be consistent with transfer_threadproc.

bvernoux commented 3 years ago

Could you confirm on your side that the memory leaks(and so all transfer pending are correctly stopped/freed) are fixed when the transfer is stopped by removing USB cable (with that fix) ?

johanhedin commented 3 years ago

Yes, the memory leaks seen using master are all gone when running against this branch.

I have done 10 runs using master and got memory leaks 4 out of 10 times. When doing the same test with this fix, no memory leaks were observed.

bvernoux commented 3 years ago

Thanks for your contribution