Fix crash in NimBLEDevice::deleteClient when notification arrives.

While deleting the client attribute database, if a notification occurs there is a possibility of
concurrency causing an exception. This fixes that by setting a flag before calling disconnect in
the deleteClient function to prevent processing further notifications.
This commit is contained in:
h2zero 2021-01-12 14:01:44 -07:00
parent b807321d1b
commit 28573f5abe

View file

@ -165,6 +165,9 @@ void NimBLEDevice::stopAdvertising() {
return false; return false;
} }
// Set the connection established flag to false to stop notifications
// from accessing the attribute vectors while they are being deleted.
pClient->m_connEstablished = false;
int rc =0; int rc =0;
if(pClient->isConnected()) { if(pClient->isConnected()) {
@ -176,6 +179,10 @@ void NimBLEDevice::stopAdvertising() {
while(pClient->isConnected()) { while(pClient->isConnected()) {
taskYIELD(); taskYIELD();
} }
// Since we set the flag to false the app will not get a callback
// in the disconnect event so we call it here for good measure.
pClient->m_pClientCallbacks->onDisconnect(pClient);
} else if(pClient->m_pTaskData != nullptr) { } else if(pClient->m_pTaskData != nullptr) {
rc = ble_gap_conn_cancel(); rc = ble_gap_conn_cancel();
if (rc != 0 && rc != BLE_HS_EALREADY) { if (rc != 0 && rc != BLE_HS_EALREADY) {