core: Fix do_close locking
authorHans de Goede <hdegoede@redhat.com>
Mon, 6 Jun 2016 15:42:12 +0000 (17:42 +0200)
committerNathan Hjelm <hjelmn@me.com>
Wed, 17 Aug 2016 18:52:40 +0000 (12:52 -0600)
Put the lock / unlock calls around the part of the code which actually
checks the flags which the lock protect.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/core.c
libusb/version_nano.h

index d1e93c8..99aab7b 100644 (file)
@@ -1351,6 +1351,7 @@ static void do_close(struct libusb_context *ctx,
                if (transfer->dev_handle != dev_handle)
                        continue;
 
+               usbi_mutex_lock(&itransfer->lock);
                if (!(itransfer->state_flags & USBI_TRANSFER_DEVICE_DISAPPEARED)) {
                        usbi_err(ctx, "Device handle closed while transfer was still being processed, but the device is still connected as far as we know");
 
@@ -1359,15 +1360,14 @@ static void do_close(struct libusb_context *ctx,
                        else
                                usbi_err(ctx, "A cancellation hasn't even been scheduled on the transfer for which the device is closing");
                }
+               usbi_mutex_unlock(&itransfer->lock);
 
                /* remove from the list of in-flight transfers and make sure
                 * we don't accidentally use the device handle in the future
                 * (or that such accesses will be easily caught and identified as a crash)
                 */
-               usbi_mutex_lock(&itransfer->lock);
                list_del(&itransfer->list);
                transfer->dev_handle = NULL;
-               usbi_mutex_unlock(&itransfer->lock);
 
                /* it is up to the user to free up the actual transfer struct.  this is
                 * just making sure that we don't attempt to process the transfer after
index 9fb8855..6995b33 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11134
+#define LIBUSB_NANO 11135