Fix segmentation fault in libusb_init() if usbi_backend.init() fails
authorAnkur Verma <ankurv@microsoft.com>
Tue, 14 Sep 2021 01:25:30 +0000 (18:25 -0700)
committerTormod Volden <debian.tormod@gmail.com>
Thu, 23 Sep 2021 08:52:11 +0000 (10:52 +0200)
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

libusb/core.c
libusb/version_nano.h

index f0844bf..d05357d 100644 (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;
index 61bd5b0..f754220 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11653
+#define LIBUSB_NANO 11654