Skip to content

Commit

Permalink
Close the libusb handle if returning failure from open()
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Nov 20, 2023
1 parent 860108f commit dcf596c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gusb/gusb-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,15 @@ _g_usb_device_open_internal(GUsbDevice *self, GError **error)

/* open device */
rc = libusb_open(priv->device, &priv->handle);
return g_usb_device_libusb_error_to_gerror(self, rc, error);
if (!g_usb_device_libusb_error_to_gerror(self, rc, error)) {
if (priv->handle != NULL)
libusb_close(priv->handle);
priv->handle = NULL;
return FALSE;
}

/* success */
return TRUE;
}

/**
Expand Down

0 comments on commit dcf596c

Please sign in to comment.