Fix 5 memory leaks in WiFiScan.cpp#1111
Open
tropicsquirrel wants to merge 1 commit intojustcallmekoko:masterfrom
Open
Fix 5 memory leaks in WiFiScan.cpp#1111tropicsquirrel wants to merge 1 commit intojustcallmekoko:masterfrom
tropicsquirrel wants to merge 1 commit intojustcallmekoko:masterfrom
Conversation
1. Free generateRandomName() result in GetUniversalAdvertisementData(). The no-arg generateRandomName() in utils.h returns a malloc'd string. The Microsoft Swiftpair case calls this every advertising cycle but never frees the result, leaking ~6 bytes per cycle. 2-3. Free AccessPoint.stations LinkedList in clearAPs() and RunAPScan(). Each AccessPoint contains a heap-allocated LinkedList<uint16_t>* stations. Neither clearAPs() nor the `delete access_points` in RunAPScan() frees these inner lists, leaking ~24+ bytes per AP per scan cycle. 4. Clear probe_req_ssids in StopScan(). The list is only cleared when starting WIFI_SCAN_PROBE, but probe requests are captured by multiple sniffer modes. Without clearing on stop, the list grows indefinitely across scan cycles. 5. Clear airtags and flippers lists in StopScan(). Both lists get entries added during BT scans but are never cleared, accumulating across scan cycles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes 5 memory leaks, as reported by
getFreeHeap()inWiFiScan.cppfound during testing. Each leak causes heap to shrink by a few KB per scan cycle, eventually leading to instability on long-running devices.Fixes
generateRandomName()result not freed — InGetUniversalAdvertisementData(), the Microsoft Swiftpair case callsgenerateRandomName()(the no-arg version inutils.h) which returns amalloc'd string. The result was never freed, leaking ~6 bytes per advertising cycle (~100x/sec during spam).AccessPoint.stationsnot freed inclearAPs()— EachAccessPointhas a heap-allocatedLinkedList<uint16_t>* stations.clearAPs()removes list nodes but never deletes the inner stations lists, leaking ~24+ bytes per AP per scan cycle.AccessPoint.stationsnot freed inRunAPScan()— Same issue:delete access_pointsdestroys the outer list but doesn't follow thestationspointers.probe_req_ssidsnever cleared on scan stop — The list is only cleared when startingWIFI_SCAN_PROBE, but probe requests are captured by multiple sniffer modes (beacon, deauth, EAPOL). Without clearing on stop, the list grows indefinitely across scan cycles.airtagsandflippersnever cleared on scan stop — Both lists accumulate entries during BT scans but are never cleared, growing across scan cycles.Testing
Tested on ESP32-S3 (8MB PSRAM).
Test plan