diff options
author | Daniel Drake <dan@reactivated.net> | 2010-05-27 19:24:49 -0400 |
---|---|---|
committer | Daniel Drake <dan@reactivated.net> | 2010-05-27 19:24:49 -0400 |
commit | 0e77f017fd3d1bdec4aced0429a380d3e434081b (patch) | |
tree | eb91c313388cc8e9d666ce2eb29a9c72981c68bd /libusb/core.c | |
parent | b03de9d07bf9a6b0c4e6cba9ec06b5271a22e621 (diff) | |
download | libusbx-0e77f017fd3d1bdec4aced0429a380d3e434081b.tar.gz |
Fix libusb_init() error handling
9996ccaed7 introduced a problem in that mutexes could be destroyed
in the error handling codepath before they had been created.
Pointed out by Michael Plante.
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/libusb/core.c b/libusb/core.c index 3e92f85..a8f0637 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1480,7 +1480,7 @@ API_EXPORTED int libusb_init(libusb_context **context) if (usbi_backend->init) { r = usbi_backend->init(ctx); if (r) - goto err; + goto err_free_ctx; } usbi_mutex_init(&ctx->usb_devs_lock, NULL); @@ -1492,7 +1492,7 @@ API_EXPORTED int libusb_init(libusb_context **context) if (r < 0) { if (usbi_backend->exit) usbi_backend->exit(); - goto err; + goto err_destroy_mutex; } usbi_mutex_static_lock(&default_context_lock); @@ -1506,9 +1506,10 @@ API_EXPORTED int libusb_init(libusb_context **context) *context = ctx; return 0; -err: +err_destroy_mutex: usbi_mutex_destroy(&ctx->open_devs_lock); usbi_mutex_destroy(&ctx->usb_devs_lock); +err_free_ctx: free(ctx); return r; } |