darwin: do not reset darwin_cached_devices on last call to libusb_exit
authorNathan Hjelm <hjelmn@google.com>
Sun, 6 Jun 2021 15:29:41 +0000 (09:29 -0600)
committerNathan Hjelm <hjelmn@google.com>
Sun, 6 Jun 2021 15:32:28 +0000 (09:32 -0600)
This fixes a bug in the change that removed the library destructor function. We should not
be setting the darwin_cached_devices next and prev pointers to NULL as other parts of
libusb may still have references to the devices (hotplug for example). When those references
are release it may modify darwin_cached_devices. This commit fixes the issue by only
initializing darwin_cached_devices on the very first call to libusb_init and not modifying
darwin_cached_devices in libusb_exit (beyond unrefing the devices).

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/darwin_usb.c
libusb/version_nano.h

index acfdf97d988a9cc9fc9b8cc3459b46afe549da6c..de070c63700881c5e83f4925512259b82ffd4cd2 100644 (file)
@@ -572,8 +572,6 @@ static void darwin_cleanup_devices(void) {
   list_for_each_entry_safe(dev, next, &darwin_cached_devices, list, struct darwin_cached_device) {
     darwin_deref_cached_device(dev);
   }
-
-  darwin_cached_devices.prev = darwin_cached_devices.next = NULL;
 }
 
 static int darwin_init(struct libusb_context *ctx) {
@@ -584,9 +582,10 @@ static int darwin_init(struct libusb_context *ctx) {
 
   do {
     if (first_init) {
-      assert (NULL == darwin_cached_devices.next);
-      list_init (&darwin_cached_devices);
-
+      if (NULL == darwin_cached_devices.next) {
+        list_init (&darwin_cached_devices);
+      }
+      assert(list_empty(&darwin_cached_devices));
 #if !defined(HAVE_CLOCK_GETTIME)
       /* create the clocks that will be used if clock_gettime() is not available */
       host_name_port_t host_self;
index 152410906477920bf551beffd3f2260685ea8bfa..9db83c01cc8ac748287ece3af9898acb305d30a5 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11617
+#define LIBUSB_NANO 11618