Prevent notifications from triggering exception while deleting services.

If we client just connected and a notification comes before deleting services it could cause an exception
when accessing a vector that is being deleted. This will check the connection established flag before
processing of notifications.
This commit is contained in:
h2zero 2021-01-12 13:58:12 -07:00
parent 765d5b1be7
commit 4f4883d6ba

View file

@ -260,13 +260,13 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
return false; return false;
} else { } else {
NIMBLE_LOGI(LOG_TAG, "Connection established"); NIMBLE_LOGI(LOG_TAG, "Connection established");
m_connEstablished = true;
} }
if(deleteAttibutes) { if(deleteAttibutes) {
deleteServices(); deleteServices();
} }
m_connEstablished = true;
m_pClientCallbacks->onConnect(this); m_pClientCallbacks->onConnect(this);
NIMBLE_LOGD(LOG_TAG, "<< connect()"); NIMBLE_LOGD(LOG_TAG, "<< connect()");
@ -840,6 +840,12 @@ uint16_t NimBLEClient::getMTU() {
if(client->m_conn_id != event->notify_rx.conn_handle) if(client->m_conn_id != event->notify_rx.conn_handle)
return 0; return 0;
// If a notification comes before this flag is set we might
// access a vector while it is being cleared in connect()
if(!client->m_connEstablished) {
return 0;
}
NIMBLE_LOGD(LOG_TAG, "Notify Recieved for handle: %d", NIMBLE_LOGD(LOG_TAG, "Notify Recieved for handle: %d",
event->notify_rx.attr_handle); event->notify_rx.attr_handle);