fix(ble): readValue memory leak bug for multiple reads#12448
Conversation
👋 Hello desaikaran1976, 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 ...
Review and merge process you can expect ...
|
The buffer allocated during readValue() was not freed when the function was called repeatedly. This caused a memory leak during repeated reads.
70821e3 to
e2b70fc
Compare
free(NULL) is safe according to the C standard, so the explicit null check is unnecessary and was removed following maintainer suggestion. Co-Authored-By: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com>
17b67c8 to
c83eea0
Compare
Test Results101 files 101 suites 29m 36s ⏱️ Results for commit 5adcd20. |
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]
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fixes #12446
Problem:
If readValue() is done only once per pClient existence or if services are cleared then there is no issue. If readValue() is done multiple times previous m_rawData pointer is lost leading to memory leak.
Solution:
Before assigning new memory for the next readValue() or readUInt16() if m_rawData is freed if not nullptr.
Used code suggested in #12446 using xiao esp32 s3