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.
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);
if (r < 0) {
if (usbi_backend->exit)
usbi_backend->exit();
- goto err;
+ goto err_destroy_mutex;
}
usbi_mutex_static_lock(&default_context_lock);
*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;
}