Only initialize the default context when it is requested
authorLudovic Rousseau <rousseau@debian.org>
Mon, 21 Jun 2010 08:19:29 +0000 (10:19 +0200)
committerDaniel Drake <dan@reactivated.net>
Tue, 22 Jun 2010 23:43:44 +0000 (18:43 -0500)
libusb/core.c

index f16a05a..ac10266 100644 (file)
@@ -1532,15 +1532,15 @@ API_EXPORTED int libusb_init(libusb_context **context)
                goto err_destroy_mutex;
        }
 
-       if (!usbi_default_context) {
+       if (context) {
+               *context = ctx;
+       } else if (!usbi_default_context) {
                usbi_dbg("created default context");
                usbi_default_context = ctx;
                default_context_refcnt++;
        }
        usbi_mutex_static_unlock(&default_context_lock);
 
-       if (context)
-               *context = ctx;
        return 0;
 
 err_destroy_mutex: