Closed qmfrederik closed 5 years ago
I have encountered this problem, too. I preferred option 3, which can support handling multiple callbacks, because i want to do that in one process with multiple threads, but now crashed.
Fixed with commit a6b542b389d0536d2730c1721164a712ec2f020e. New API:
int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data);
int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context);
enjoy
If you call
usbmuxd_subscribe
more than once, but do not callusbmuxd_unsubscribe
in between, thedevice_monitor
thread which is created byusbmuxd_subscribe
is started multiple times.When messages such as
MESSAGE_DEVICE_REMOVE
are received, all of these threads will attempt to find the device, and remove the handle for that device. This leads to race conditions and ultimately tofree(devinfo)
being called twice.I see three options to resolve this:
usbmuxd_subscribe
check whether another callback is already registered, and if so, return-EALREADY
to let the caller know this was not a valid operationusbmuxd_unsubscribe
and register the new callbackMy preference currently goes to 1, and I can submit a PR for this, but before I do that, I'd like to check with you whether this is the project's preferred option.