Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential crash when libusb_detach_kernel_driver fails #363

Merged
merged 1 commit into from
Jan 3, 2022
Merged

Conversation

Youw
Copy link
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.

None yet

2 participants