From e4d2e991f1c5db2cedb56f53d8081cfafa7c8f9e Mon Sep 17 00:00:00 2001 From: h2zero Date: Mon, 9 Dec 2024 09:28:18 -0700 Subject: [PATCH] Fix crash when peer disconnects from the server. If the server has not created a client instance then the device would crash when the peer disconnects due to nullptr access. --- src/NimBLEServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NimBLEServer.cpp b/src/NimBLEServer.cpp index 21c10f4..9fdbe3e 100644 --- a/src/NimBLEServer.cpp +++ b/src/NimBLEServer.cpp @@ -397,7 +397,7 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) { } } - if (pServer->m_pClient->m_connHandle == event->disconnect.conn.conn_handle) { + if (pServer->m_pClient && pServer->m_pClient->m_connHandle == event->disconnect.conn.conn_handle) { // If this was also the client make sure it's flagged as disconnected. pServer->m_pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE; }