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

[WiFiScan] Allow allocation in _scanDone() to fail and prevent memory leak #10335

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

TD-er
Copy link
Contributor

@TD-er TD-er commented Sep 12, 2024

Description of Change

When there are many AP's seen during a scan, the allocation of _scanResult may fail.
Thus add (std::nothrow) to the new 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.

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.
Copy link
Contributor

github-actions bot commented Sep 12, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "[WiFiScan] Allow allocation to fail and prevent memory leak":
    • summary looks empty
    • type/action looks empty
  • the commit message "[WiFiScan] Use nullptr instead of 0":
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

⚠️

The source branch "bugfix/wifiscanclass_scanDone" incorrect format:

  • contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS).
    Please rename your branch.
Messages
📖 You might consider squashing your 3 commits (simplifying branch history).

👋 Hello TD-er, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against b063e8f

Copy link
Contributor

github-actions bot commented Sep 12, 2024

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.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32S30⚠️ +320.000.00000.000.00
ESP32S20⚠️ +360.000.00000.000.00
ESP32C30⚠️ +280.000.00000.000.00
ESP32C60⚠️ +280.000.00000.000.00
ESP320⚠️ +320.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
WiFi/examples/FTM/FTM_Initiator⚠️ +320⚠️ +320⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/FTM/FTM_Responder⚠️ +320⚠️ +320⚠️ +260⚠️ +280⚠️ +280
WiFi/examples/SimpleWiFiServer⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WPS⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WiFiAccessPoint⚠️ +200⚠️ +280⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WiFiBlueToothSwitch⚠️ +280--⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WiFiClient⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/WiFiClientBasic⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/WiFiClientConnect⚠️ +320⚠️ +360⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WiFiClientEnterprise⚠️ +240⚠️ +320⚠️ +240⚠️ +240⚠️ +240
WiFi/examples/WiFiClientEvents⚠️ +320⚠️ +320⚠️ +240⚠️ +260⚠️ +280
WiFi/examples/WiFiClientStaticIP⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +280
WiFi/examples/WiFiExtender⚠️ +320⚠️ +320⚠️ +240⚠️ +260⚠️ +280
WiFi/examples/WiFiIPv6⚠️ +280⚠️ +320⚠️ +240⚠️ +220⚠️ +280
WiFi/examples/WiFiMulti⚠️ +320⚠️ +320⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/WiFiMultiAdvanced⚠️ +240⚠️ +200⚠️ +260⚠️ +260⚠️ +280
WiFi/examples/WiFiScan⚠️ +320⚠️ +360⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/WiFiScanAsync⚠️ +320⚠️ +320⚠️ +280⚠️ +240⚠️ +320
WiFi/examples/WiFiScanDualAntenna⚠️ +320⚠️ +320⚠️ +240⚠️ +260⚠️ +320
WiFi/examples/WiFiScanTime⚠️ +320⚠️ +320⚠️ +260⚠️ +240⚠️ +320
WiFi/examples/WiFiSmartConfig⚠️ +320⚠️ +280⚠️ +260⚠️ +240⚠️ +280
WiFi/examples/WiFiTelnetToSerial⚠️ +280⚠️ +280⚠️ +240⚠️ +240⚠️ +320
WiFi/examples/WiFiUDPClient⚠️ +280⚠️ +200⚠️ +240⚠️ +240⚠️ +280

Copy link
Contributor

github-actions bot commented Sep 12, 2024

Test Results

 56 files   -  83   56 suites   - 83   4m 34s ⏱️ - 1h 37m 22s
 21 tests  -   9   21 ✅  -   9  0 💤 ±0  0 ❌ ±0 
135 runs   - 168  135 ✅  - 168  0 💤 ±0  0 ❌ ±0 

Results for commit b063e8f. ± Comparison against base commit 9e60bbe.

This pull request removes 9 tests.
performance.coremark.test_coremark ‑ test_coremark
performance.fibonacci.test_fibonacci ‑ test_fibonacci
performance.psramspeed.test_psramspeed ‑ test_psramspeed
performance.ramspeed.test_ramspeed ‑ test_ramspeed
performance.superpi.test_superpi ‑ test_superpi
test_touch_errors
test_touch_interrtupt
test_touch_read
validation.periman.test_periman ‑ test_periman

♻️ This comment has been updated with latest results.

@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Sep 16, 2024
@me-no-dev me-no-dev merged commit 3978870 into espressif:master Sep 16, 2024
68 checks passed
@TD-er TD-er deleted the bugfix/wifiscanclass_scanDone branch September 16, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Merge Pull Request is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants