Hi Martin,
Many thanks for sharing the insights.
For my understanding, librtlsdr uses libusb_handle_events_timeout_completed which should terminate early if the dev->async_cancel flag is set. Is there still a purpose to call libusb_interrupt_event_handler in this case or is it required to guarantee the handler inspects the flag immediately, before any timeout or a new event (i.e. like a notification)? That did not became clear to me from the libusb documentation.
The easiest way I can see now to assess we can safely free up the transfers is to count the live transfers (increase a counter by one if there was a successful resubmit) and reduce by one at the start of a libusb callback. It is then safe to terminate if the counter is zero. I have implemented that here: https://github.com/jvde-github/rtl-sdr/commit/325d47f1f3c1d9fbece98770348283...
Seems to work really well but given the various versions of libusb and supported platforms around, I am hesitant to submit as patch until it solves a reported problem.
Thanks, Jasper