Workarround to avoid the SEGFAULT case on libusb#12
Merged
antoniovazquezblanco merged 1 commit intousbbluetooth:mainfrom Dec 16, 2025
Merged
Workarround to avoid the SEGFAULT case on libusb#12antoniovazquezblanco merged 1 commit intousbbluetooth:mainfrom
antoniovazquezblanco merged 1 commit intousbbluetooth:mainfrom
Conversation
Member
|
Hey! Many thanks for looking into this @sha0coder! It makes sense to me... It would be better if we could close the socket before the delete but there seems to be no intuitive way to do so... Thanks for taking the time. Merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the python program termiantes, it calls
SuperSocket.__del__and this triggersUsbBluetoothSocket.close()that closes the usbbluetooth controller.The usbbluetooth controller shouldn't be closed from a
__del__because it callsis_kernel_driver_activeIf pyusb's
is_kernel_driver_activeis called from a destructor will send a bad handle to libusb and will segfault always.usbbluetooth cannot detect if it's being called from a destructor, and not calling
is_kernel_driver_activewill fix it but should be called in normal situations.pyusb is a simply ctypes wrapper, it's like calling direclty the c libusb.
Having said that the best way is disabling
SuperSocket.__del__by overriding it onUsbBluetoothSocket.These scripts triggers the segfault:
Trigger1.py:
Trigger2.py: