summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Hjelm <hjelmn@google.com>2021-06-06 09:29:41 -0600
committerNathan Hjelm <hjelmn@google.com>2021-06-06 09:32:28 -0600
commit676076ce6cbed8331a22c33ca84b9cae326cff5b (patch)
tree373f4c4186dbc2015e52cf3ebd80198cbeaaa952
parent32a22069428cda9d63aa666e92fb8882a83d4515 (diff)
downloadlibusb-676076ce6cbed8331a22c33ca84b9cae326cff5b.tar.gz
darwin: do not reset darwin_cached_devices on last call to libusb_exit
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>
-rw-r--r--libusb/os/darwin_usb.c9
-rw-r--r--libusb/version_nano.h2
2 files changed, 5 insertions, 6 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index acfdf97..de070c6 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -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;
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 1524109..9db83c0 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11617
+#define LIBUSB_NANO 11618