-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
[WiFiScan] Allow allocation in _scanDone() to fail and prevent memory leak #10335
[WiFiScan] Allow allocation in _scanDone() to fail and prevent memory leak #10335
Conversation
When there are many AP's seen during a scan, the allocation of `_scanResult` may fail. Thus add `(std::nothrow)` to the `new` call. Also it is possible the array was still present before allocating a new one.
👋 Hello TD-er, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
Memory usage test (comparing PR against master branch)The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.
Click to expand the detailed deltas report [usage change in BYTES]
|
Test Results 56 files - 83 56 suites - 83 4m 34s ⏱️ - 1h 37m 22s Results for commit b063e8f. ± Comparison against base commit 9e60bbe. This pull request removes 9 tests.
♻️ This comment has been updated with latest results. |
Description of Change
When there are many AP's seen during a scan, the allocation of
_scanResult
may fail.Thus add
(std::nothrow)
to thenew
call. Without it, the next check for a valid pointer was not even done as the application would already have crashed.Also it is possible the array was still present before allocating a new one, so we must make sure it is deleted first.
Related links
Follow-up of this PR: #10312
Possible (known) issue
There is 1 possible known issue left which is not being dealt with by this PR.
Since the
_scanDone()
function is called from a callback from an async scan, in theory it is possible someone is still processing a previous scan result via_getScanInfoByIndex()
.However if this does happen, then without this fix we would have had a memory leak for sure.
To work around such corner cases, quite a lot of code changes may be needed, which is out of scope of this PR.