Skip to content

Commit

Permalink
Fix potential crash when libusb_detach_kernel_driver fails (#363)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Youw authored Jan 3, 2022
1 parent af6c601 commit f0a4a1f
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ static int hidapi_initialize_device(hid_device *dev, const struct libusb_interfa
if (libusb_kernel_driver_active(dev->device_handle, intf_desc->bInterfaceNumber) == 1) {
res = libusb_detach_kernel_driver(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
libusb_close(dev->device_handle);
LOG("Unable to detach Kernel Driver\n");
return 0;
}
Expand Down

0 comments on commit f0a4a1f

Please sign in to comment.