From 4f4883d6baa68cbba786224febc8649e3df0c871 Mon Sep 17 00:00:00 2001 From: h2zero Date: Tue, 12 Jan 2021 13:58:12 -0700 Subject: [PATCH] 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. --- src/NimBLEClient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index b0a69d3..3f4d014 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -260,13 +260,13 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) { return false; } else { NIMBLE_LOGI(LOG_TAG, "Connection established"); - m_connEstablished = true; } if(deleteAttibutes) { deleteServices(); } + m_connEstablished = true; m_pClientCallbacks->onConnect(this); NIMBLE_LOGD(LOG_TAG, "<< connect()"); @@ -840,6 +840,12 @@ uint16_t NimBLEClient::getMTU() { if(client->m_conn_id != event->notify_rx.conn_handle) 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", event->notify_rx.attr_handle);