diff options
author | Ankur Verma <ankurv@microsoft.com> | 2021-09-13 18:25:30 -0700 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2021-09-23 10:52:11 +0200 |
commit | 6929b8270170a76e9af30d0a9e95c2081f4372b0 (patch) | |
tree | cf00ec7ed9fe754c0cfe5bfcb8e85ead65cbd0b7 | |
parent | 7d7733a3773df271396e473252083d051a4e4f5c (diff) | |
download | libusb-6929b8270170a76e9af30d0a9e95c2081f4372b0.tar.gz |
Fix segmentation fault in libusb_init() if usbi_backend.init() fails
If the backend init fails, the control goes to err_io_exit which tries
to clean up hotplug related lists that aren't initialized. Moving
hotplug_init before makes sure the lists are valid so if backend init
fails they get cleaned up without errors.
Closes #989
-rw-r--r-- | libusb/core.c | 3 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/libusb/core.c b/libusb/core.c index f0844bf..d05357d 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -2342,13 +2342,14 @@ int API_EXPORTED libusb_init(libusb_context **ctx) list_add(&_ctx->list, &active_contexts_list); usbi_mutex_static_unlock(&active_contexts_lock); + usbi_hotplug_init(_ctx); + if (usbi_backend.init) { r = usbi_backend.init(_ctx); if (r) goto err_io_exit; } - usbi_hotplug_init(_ctx); if (ctx) *ctx = _ctx; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 61bd5b0..f754220 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11653 +#define LIBUSB_NANO 11654 |