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.
Fix Memory Leaks in System Extension
Fixes #616, where 1+ memory leak(s) in the system extension could cause memory to grow from ~100 MB to 10+ GB, causing network failures.
Note: This was largerly generated by Claude. I ran many passes to try to get the best possible outcome. However, since I can't sign the extension and can't test, I can't vouch for whether this actually works (or is even the proper approach).
Problem
The system extension accumulates memory over time (versions 2.4.3 - 3.1.5), eventually consuming 10+ GB RAM and breaking network connectivity.
Root causes
pendingAlerts/relatedFlowsdictionariesprocessRelatedFlow)Solution
Break Retain Cycles
A. Use weak-strong dance pattern in alert reply blocks
B. Prevents self from being retained by async XPC callbacks
Track All Flows
A. Add
pendingAlertsdictionary to track flows awaiting user responseB. Ensures flows aren't lost when user doesn't respond
Fix processRelatedFlow Bug
A. Resume flows BEFORE removing from dictionary
B. Handle pause verdict correctly (keep in dictionary for next round)
Cleanup Orphaned Flows
A. Add
isFlowOrphanedhelper andcleanupOrphanedFlowsmethodB. Resume orphaned flows with
dropVerdict(critical for system to release)C. Triggers: every 5 minutes + on XPC failure
Dealloc Cleanup
A. Resume all flows during dealloc using
resumeFlowshelperB. Prevents flows from remaining paused on extension shutdown
Race Condition Prevention
A. Check if flow still in
pendingAlertsbefore processing user responseB. Prevents double-resume if cleanup already handled flow
C. Ensures user's choice isn't applied to stale flows
All flow resume operations use shared
resumeFlowshelper to eliminate code duplication and ensure consistent error handling.Testing
Unit tests
Run tests:
cd LuLu/Tests && bash run_tests.shIntegration testing
Requires system extension runtime (which I can't sign and thus cannot run/test).
Expected behavior
Edge Cases Handled
@synchronized)