From f0a4a1fa2eced8ca69a1c89c8b3f807125670076 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Mon, 3 Jan 2022 14:16:37 +0200 Subject: [PATCH] Fix potential crash when libusb_detach_kernel_driver fails (#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. --- libusb/hid.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libusb/hid.c b/libusb/hid.c index 756a5916c..c9e86c07a 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -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; }