Skip to content

Conversation

@lucasssvaz
Copy link
Member

Description of Change

This pull request enhances memory management and object copying for the BLEAdvertisedDevice class, ensuring safe handling of the advertising payload buffer. The changes add a destructor, copy constructor, and assignment operator, and improve how the payload buffer is allocated, copied, and freed to avoid memory leaks and ensure correct behavior when objects are copied or reassigned.

Memory management and object lifecycle improvements:

  • Added a destructor, copy constructor, and assignment operator to BLEAdvertisedDevice to properly manage the dynamic m_payload buffer, ensuring deep copies and freeing memory when needed. (libraries/BLE/src/BLEAdvertisedDevice.cpp, libraries/BLE/src/BLEAdvertisedDevice.h) [1] [2]
  • Modified the constructor to initialize m_payload and m_payloadLength to safe default values. (libraries/BLE/src/BLEAdvertisedDevice.cpp)

Payload buffer handling improvements:

  • Updated parseAdvertisement to always make a copy of the payload buffer and to append scan response data safely, preventing use-after-free or double-free issues. (libraries/BLE/src/BLEAdvertisedDevice.cpp)
  • Improved setPayload to allocate, copy, and append payload data safely, with error checking and freeing of previous buffers as needed. (libraries/BLE/src/BLEAdvertisedDevice.cpp)

Test Scenarios

Tested locally

Related links

Closes #12075

@lucasssvaz lucasssvaz self-assigned this Dec 2, 2025
@lucasssvaz lucasssvaz requested a review from SuGlider as a code owner December 2, 2025 15:12
@lucasssvaz lucasssvaz added the Area: BLE Issues related to BLE label Dec 2, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello lucasssvaz, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for 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.
- 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 81a88ef

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

Test Results

 76 files   76 suites   18m 34s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commit 711ccfa.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

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
ESP32C50⚠️ +9260.00⚠️ +0.12000.000.00
ESP32P40⚠️ +9280.00⚠️ +0.12000.000.00
ESP32S30⚠️ +7920.00⚠️ +0.13000.000.00
ESP32C30⚠️ +9260.00⚠️ +0.15000.000.00
ESP32C60⚠️ +9300.00⚠️ +0.13000.000.00
ESP32H20⚠️ +9260.00⚠️ +0.13000.000.00
ESP320⚠️ +8440.00⚠️ +0.08000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/BLE/examples/Beacon_Scanner⚠️ +9260⚠️ +9280⚠️ +7920⚠️ +9260⚠️ +9300⚠️ +9260⚠️ +8120
libraries/BLE/examples/Client⚠️ +4600⚠️ +4640⚠️ +3320⚠️ +4600⚠️ +4620⚠️ +4600⚠️ +3120
libraries/BLE/examples/Client_multiconnect⚠️ +3740⚠️ +3700⚠️ +2880⚠️ +3700⚠️ +3740⚠️ +3740⚠️ +2840
libraries/BLE/examples/Client_secure_static_passkey⚠️ +4640⚠️ +4640⚠️ +3680⚠️ +4640⚠️ +4660⚠️ +4640⚠️ +3160
libraries/BLE/examples/EddystoneTLM_Beacon⚠️ +9240⚠️ +9220⚠️ +7840⚠️ +9240⚠️ +9240⚠️ +9240⚠️ +8160
libraries/BLE/examples/EddystoneURL_Beacon⚠️ +9260⚠️ +9240⚠️ +7840⚠️ +9260⚠️ +9240⚠️ +9260⚠️ +8040
libraries/BLE/examples/Notify⚠️ +9120⚠️ +9120⚠️ +7760⚠️ +9140⚠️ +9140⚠️ +9120⚠️ +8040
libraries/BLE/examples/Scan⚠️ +9200⚠️ +9200⚠️ +7880⚠️ +9200⚠️ +9200⚠️ +9200⚠️ +8200
libraries/BLE/examples/Server⚠️ +9160⚠️ +9160⚠️ +7800⚠️ +9180⚠️ +9160⚠️ +9160⚠️ +8000
libraries/BLE/examples/Server_multiconnect⚠️ +9120⚠️ +9140⚠️ +7760⚠️ +9140⚠️ +9140⚠️ +9120⚠️ +8040
libraries/BLE/examples/Server_secure_authorization⚠️ +9180--⚠️ +7920⚠️ +9180⚠️ +9180⚠️ +9180--
libraries/BLE/examples/Server_secure_static_passkey⚠️ +9120⚠️ +9140⚠️ +7880⚠️ +9120⚠️ +9120⚠️ +9120⚠️ +7840
libraries/BLE/examples/UART⚠️ +9120⚠️ +9140⚠️ +7760⚠️ +9120⚠️ +9120⚠️ +9120⚠️ +8120
libraries/BLE/examples/Write⚠️ +9160⚠️ +9160⚠️ +7880⚠️ +9200⚠️ +9160⚠️ +9160⚠️ +8000
libraries/BLE/examples/iBeacon⚠️ +9240⚠️ +9240⚠️ +7880⚠️ +9220⚠️ +9240⚠️ +9240⚠️ +8440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BLE Issues related to BLE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESP32-S3 BLE Active Scan Regression: Failure to Process/Merge Scan Response Data (e.g., Service Data Type 0x16)

3 participants