summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-04-07 12:43:08 +0200
committerTormod Volden <debian.tormod@gmail.com>2022-04-09 10:00:13 +0200
commitff05357a839dd1f65caf736ded2476eaa135fe06 (patch)
tree3c1d87c3b8b659a7a7fe5fa83bf9c45dd5a49a07
parent32f3c6db957da09f78de18439c61ab1b8fe6358f (diff)
downloadlibusb-ff05357a839dd1f65caf736ded2476eaa135fe06.tar.gz
darwin: Fix crash in log handler when stopping event thread
The darwin event thread (in contrast to other OS implementations) tries to log to the context that created it. However, this context is only guaranteed to be valid until the thread has started. It may be that another context is the last one to be destroyed, causing the event thread to log using an already destroyed context. Fix this by only passing on ctx where it is acceptable. Fixes #1108
-rw-r--r--libusb/os/darwin_usb.c7
-rw-r--r--libusb/version_nano.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index a457f95..388dbca 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -494,6 +494,7 @@ static void *darwin_event_thread_main (void *arg0) {
io_iterator_t libusb_rem_device_iterator;
io_iterator_t libusb_add_device_iterator;
+ /* ctx must only be used for logging during thread startup */
usbi_dbg (ctx, "creating hotplug event source");
runloop = CFRunLoopGetCurrent ();
@@ -515,7 +516,7 @@ static void *darwin_event_thread_main (void *arg0) {
kresult = IOServiceAddMatchingNotification (libusb_notification_port, kIOTerminatedNotification,
IOServiceMatching(darwin_device_class),
darwin_devices_detached,
- ctx, &libusb_rem_device_iterator);
+ NULL, &libusb_rem_device_iterator);
if (kresult != kIOReturnSuccess) {
usbi_err (ctx, "could not add hotplug event source: %s", darwin_error_str (kresult));
@@ -528,7 +529,7 @@ static void *darwin_event_thread_main (void *arg0) {
kresult = IOServiceAddMatchingNotification(libusb_notification_port, kIOFirstMatchNotification,
IOServiceMatching(darwin_device_class),
darwin_devices_attached,
- ctx, &libusb_add_device_iterator);
+ NULL, &libusb_add_device_iterator);
if (kresult != kIOReturnSuccess) {
usbi_err (ctx, "could not add hotplug event source: %s", darwin_error_str (kresult));
@@ -553,7 +554,7 @@ static void *darwin_event_thread_main (void *arg0) {
/* run the runloop */
CFRunLoopRun();
- usbi_dbg (ctx, "darwin event thread exiting");
+ usbi_dbg (NULL, "darwin event thread exiting");
/* signal the main thread that the hotplug runloop has finished. */
pthread_mutex_lock (&libusb_darwin_at_mutex);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index a04468b..30dad67 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11720
+#define LIBUSB_NANO 11722