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

Ensure cleanup on hotplug_libusb shutdown #172

Conversation

emaxx-google
Copy link
Contributor

@emaxx-google emaxx-google commented Apr 12, 2024

Make sure the hotplug_libusb cleanup code is executed on all exit
branches from the thread. This prevents memory and resource leaks
on these codepaths.

Before the commit, it was possible that the cleanup code in
HPRescanUsbBus() would be skipped if the caller
(HPEstablishUSBNotifications()) decides to exit on its own. Also
libusb_exit() was skipped in some branches.

The commit moves the cleanup code to the end of
HPEstablishUSBNotifications() and removes pthread_exit() from
HPRescanUsbBus(), so that cleanup isn't skipped.

Make sure the hotplug_libusb cleanup code is executed on all exit
branches from the thread. This prevents memory and resource leaks
on these codepaths.

Before the commit, it was possible that the cleanup code in
HPRescanUsbBus() would be skipped if the caller
(HPEstablishUSBNotifications()) decides to exit on its own. Also
libusb_exit() was skipped in some branches.

The commit moves the cleanup code to the end of
HPEstablishUSBNotifications() and removes pthread_exit() from
HPRescanUsbBus(), so that cleanup isn't skipped.
@emaxx-google emaxx-google changed the title Ensure cleanup on libusb hotplug shutdown Ensure cleanup on hotplug_libusb shutdown Apr 12, 2024
@emaxx-google emaxx-google marked this pull request as ready for review April 12, 2024 20:55
@emaxx-google
Copy link
Contributor Author

Note: there'll be a merge conflict with #172: rescan_pipe[0] will join the moved piece of cleanup code. (Github dependant PRs are weird, so I've decided to publish all changes separately. Happy to do a rebase once/if #172 lands.)

@LudovicRousseau
Copy link
Owner

Merged in 2b297eb

Note that I also modified the way the thread exits in bfcb434 by calling HPReCheckSerialReaders() to write in rescan_pipe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants