framework-arduinoespressif32: BLEClient::~BLEClient() crashes in BLERemoteService::removeCharacteristics() with double free
See original GitHub issueI presume this issue really needs to be submitted in another repository, but all repository references for framework-arduinoespressif32 go to this repo. Please enlighten me if I need to submit it elsewhere. framework-arduinoespressif32 version is 3.10004.100129 (1.0.4).
I have found that creating a BLEClient()
connection and then later calling delete
on it is a sure way of getting a crash: panic()
while freeing memory.
Digging down through the BLE stack showed that the double free is in BLERemoteService::removeCharacteristics()
. It loops over two maps, m_characteristicMap
and m_characteristicMapByHandle
, calling delete
on all the values.
But: the two maps share the same set of values (the characteristics objects), indexed by different keys. To fix, the delete loop should only be applied to m_characteristicMap
and the other map should simply be cleared without deleting the values.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Reproducing the problem which is fixed by https://github.com/espressif/arduino-esp32/pull/3973 is very easy, at least for me with ESP32 MCU. It simply requires a connection to a service with characteristics, so in the most trivial case the code will look like this:
The expected behavior would be to read the value every 10th second, but the loop() crashes on “delete pClient” with this error message:
Closing as the issue has nothing to do with the PlatformIO dev-platform.