Darwin: fix potential leak on libusb_claim_interface() error
authorVitali Lovich <vlovich@gmail.com>
Fri, 16 Sep 2011 14:48:28 +0000 (08:48 -0600)
committerPeter Stuge <peter@stuge.se>
Mon, 17 Oct 2011 14:25:50 +0000 (16:25 +0200)
libusb/os/darwin_usb.c

index 5451f23..6e9d36f 100644 (file)
@@ -1040,6 +1040,10 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
   /* get an interface to the device's interface */
   kresult = IOCreatePlugInInterfaceForService (usbInterface, kIOUSBInterfaceUserClientTypeID,
                                               kIOCFPlugInInterfaceID, &plugInInterface, &score);
+
+  /* ignore release error */
+  (void)IOObjectRelease (usbInterface);
+
   if (kresult) {
     usbi_err (HANDLE_CTX (dev_handle), "IOCreatePlugInInterfaceForService: %s", darwin_error_str(kresult));
     return darwin_to_libusb (kresult);
@@ -1050,9 +1054,6 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
     return LIBUSB_ERROR_NOT_FOUND;
   }
 
-  /* ignore release error */
-  (void)IOObjectRelease (usbInterface);
-
   /* Do the actual claim */
   kresult = (*plugInInterface)->QueryInterface(plugInInterface,
                                               CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID),