Fix application shutdown segfaults with minimal intervention #49
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.
Problem
The application experiences segmentation faults during shutdown, making it unreliable for production use.
Root Cause Analysis
After thorough debugging, the issue was identified as GTK idle callbacks (
gtk_dotted_slider_refresh_items_gui
) attempting to access freed memory during application shutdown. The segfaults occurred when:Solution
This PR implements a minimal, surgical fix that addresses the root cause directly:
g_idle_add()
ingtk_dotted_slider_refresh_items()
Changes Made
src/animations/gtk/gtk_dotted_slider_widget.c
Other files
src/app/onvif_app_shutdown.c
andsrc/gst/gstrtspplayer.c
Testing
✅ Before fix: Application segfaulted on shutdown
✅ After fix: Clean shutdown with return code 0
✅ Functionality: All features work normally during operation
✅ Multiple test runs: Consistent clean shutdown behavior
✅ No regressions: All existing functionality preserved
Benefits
Technical Details
The fix works by preventing GTK idle callbacks from being scheduled during the shutdown process. Since these callbacks were only used for animation refresh and the application is shutting down anyway, disabling them eliminates the race condition without affecting functionality.
This approach is superior to complex thread synchronization or shutdown flags because it:
Verification
The fix has been tested extensively with multiple shutdown scenarios and consistently produces clean exits without segfaults while maintaining all application functionality.
This minimal approach demonstrates that sometimes the best fix is the simplest one that directly addresses the root cause.
Pull Request opened by Augment Code with guidance from the PR author