Closed
Description
My BLE client code was structured more-or-less as
BLEClient *client = new BLEClient();
client->connect(address, type);
// interact with client
client->disconnect();
delete client;
but this is unsafe. Sometimes I get a corrupted heap, sometimes I get other crashes, possibly after running this code again (I am creating many connections to many BLE devices over a long time).
I think the problem may be that disconnect()
is asynchronous, because often my crashes are in BLEClient::gattClientEventHandler()
in the ESP_GATTC_DISCONNECT_EVT
case handler, but they can also happen in the BLE thread, or in completely unrelated code.
The workaround I have is to never delete my BLEClient objects but to cache and reuse them, but from the code (and the minimal documentation) it seems like I should have been able to create and delete them on-the-fly.