Skip to content

Commit f0a4a1f

Browse files
authored
Fix potential crash when libusb_detach_kernel_driver fails (signal11#363)
In case if libusb_detach_kernel_driver fails inside hidapi_initialize_device HIDAPI had tried to `libusb_close(dev->device_handle)` two times: - right after `libusb_detach_kernel_driver`; - outside of `hidapi_initialize_device` function; The fix: `libusb_close` the device only once. And since `hidapi_initialize_device` is not responsible for opening the device - it is not responsible for closing it either.
1 parent af6c601 commit f0a4a1f

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

libusb/hid.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,6 @@ static int hidapi_initialize_device(hid_device *dev, const struct libusb_interfa
923923
if (libusb_kernel_driver_active(dev->device_handle, intf_desc->bInterfaceNumber) == 1) {
924924
res = libusb_detach_kernel_driver(dev->device_handle, intf_desc->bInterfaceNumber);
925925
if (res < 0) {
926-
libusb_close(dev->device_handle);
927926
LOG("Unable to detach Kernel Driver\n");
928927
return 0;
929928
}

0 commit comments

Comments
 (0)