Skip to content

Commit

Permalink
hotplug_exit: Mutex protection of context device list while cleaning it
Browse files Browse the repository at this point in the history
This prevents concurrent access to the list by the event background
thread, which could still be processing a previous hotplug event and
having to modify the list.

Fixes #1366
Fixes #1445
Closes #1452
References #1406
  • Loading branch information
sonatique authored and tormodvolden committed Mar 14, 2024
1 parent 51d2c0f commit 6c0ae1a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions libusb/hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void usbi_hotplug_exit(struct libusb_context *ctx)
free(msg);
}

usbi_mutex_lock(&ctx->usb_devs_lock); /* hotplug thread might still be processing an already triggered event, possibly accessing this list as well */
/* free all discovered devices */
for_each_device_safe(ctx, dev, next_dev) {
/* remove the device from the usb_devs list only if there are no
Expand All @@ -227,6 +228,7 @@ void usbi_hotplug_exit(struct libusb_context *ctx)

libusb_unref_device(dev);
}
usbi_mutex_unlock(&ctx->usb_devs_lock);

usbi_mutex_destroy(&ctx->hotplug_cbs_lock);
}
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11885
#define LIBUSB_NANO 11886

0 comments on commit 6c0ae1a

Please sign in to comment.