From 9eea85f9ffaaa50fbf15ea704670c82854c95345 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 30 Aug 2021 23:20:02 -0700 Subject: [PATCH] Check if m_pServerCallbacks is not null before calling method. (#5603) Fixes: https://github.com/espressif/arduino-esp32/issues/5573 To reproduce: 1. Run any sample code that starts a BLE server, and does not call `setCallbacks`. 2. Connect to the device using the "LightBlue" app on iOS. 3. Observe crash shown in the issue linked above. --- libraries/BLE/src/BLEServer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/BLE/src/BLEServer.cpp b/libraries/BLE/src/BLEServer.cpp index fcb67da9..7f156eff 100644 --- a/libraries/BLE/src/BLEServer.cpp +++ b/libraries/BLE/src/BLEServer.cpp @@ -157,7 +157,9 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t case ESP_GATTS_MTU_EVT: updatePeerMTU(param->mtu.conn_id, param->mtu.mtu); - m_pServerCallbacks->onMtuChanged(this, param); + if (m_pServerCallbacks != nullptr) { + m_pServerCallbacks->onMtuChanged(this, param); + } break; // ESP_GATTS_CONNECT_EVT