Kernel panic when delete BLEClient object with descriptor characteristic#8010
Kernel panic when delete BLEClient object with descriptor characteristic#8010me-no-dev merged 4 commits intoespressif:masterfrom
Conversation
Fix kernel panic issue when trying to release BLEClient when the target device have a ble descriptor.
|
@chesterkwan - Thanks for the PR! |
|
Any updates on this @chesterkwan ? |
|
Thanks for reminding me of the pull request, too busy on other projects and nearly forgot about it. The following section is callback class to handle the connect and disconnect of the BLE device. The faulty condition is that when you try to disconnect a device with write or notify characteristic, it will cause a kernel panic. But if you try to disconnect a device only with read characteristic, everything goes fine. After drilling into the library, and find out the write and notify both characteristic include a descriptor. And the kernel panic were caused by the code trying to remove an item which have already been removed. Thanks |
Any comment? |
Sorry is there any question regarding this pull request? |
|
Hi @chesterkwan, not right now, it's awaiting the review from our side. |
lucasssvaz
left a comment
There was a problem hiding this comment.
Looks good. Just a small suggestion.
Co-authored-by: Lucas Saavedra Vaz <lucassvaz@yahoo.com.br>
|
Committed. Thanks |
Fix kernel panic issue when trying to release BLEClient when the target device have a ble descriptor.
Description of Change
When I try to release BLEClient to free memory, sometimes it causes a kernel panic. After tracing down the code, I discover that when it try to delete the characteristic map of the BLEClient, it will also have to remove the descriptors under it if it exists.
When removing the descriptor from the map in BLERemoteCharacteristic::removeDescriptors() function, the code will first remove the map entry and then will try to access that deleted entry to remove the descriptor object. Which caused the kernel panic as entry are not exist.
The fix is simply removing the line which remove the map entry, and let the following code to remove then descriptor object. The final clear after the for-loop will ensure the map being cleared.
Tests scenarios
Tested on ESP32C3 and ESP32