Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make hidapi_exit() safe by turning it into a no-op
Calling hid_exit() can lead to memory bugs if care is not taken. This has been observed as segmentation faults with the LibUSB backend, where hid_exit() calls libusb_exit(), which in turn has a well documented contract: > Deinitialize libusb. Should be called after closing all open devices > and before your application terminates. While the Linux HIDRAW backend appears to be more tolerant, there may be other backends that behave like LibUSB, or even have additional prerequisites for calling hid_exit(). On its part, HIDAPI is not clear about the requirements of hid_exit(): > This function frees all of the static data associated with HIDAPI. It > should be called at the end of execution to avoid memory leaks. Because of these reasons, there is no alternative but to threat hid_exit() as a very unsafe function. As such, any wrapper we provide for it – in practice, hidapi_exit() – would also have to be made safe. Unfortunately, doing that is non-trivial, and possibly quite expensive. Instead, turn hidapi_exit() into a no-op for now. The HIDAPI library will still be cleanly finalized before the program terminates, through another – automatic – mechanism. Related: trezor#128 ("Fatal Python error: Segmentation fault on 0.11.0.post2")
- Loading branch information