Skip to content

Fix potential crash when libusb_detach_kernel_driver fails#363

Merged
Youw merged 1 commit intomasterfrom
fix-crash
Jan 3, 2022
Merged

Fix potential crash when libusb_detach_kernel_driver fails#363
Youw merged 1 commit intomasterfrom
fix-crash

Conversation

@Youw
Copy link
Copy Markdown
Member

@Youw Youw commented Dec 30, 2021

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.

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.
@Youw Youw requested a review from a team December 30, 2021 16:25
@mcuee mcuee added the libusb Related to libusb backend label Dec 31, 2021
@Youw Youw merged commit f0a4a1f into master Jan 3, 2022
@Youw Youw deleted the fix-crash branch January 3, 2022 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libusb Related to libusb backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants