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
This commit is contained in:
Ankur Verma
2021-09-13 18:25:30 -07:00
committed by Tormod Volden
parent 7d7733a377
commit 6929b82701
2 changed files with 3 additions and 2 deletions

View File

@@ -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;

View File

@@ -1 +1 @@
#define LIBUSB_NANO 11653
#define LIBUSB_NANO 11654