From 16b6bdbddf70935feb1934cfbf0e9b9ce02dda49 Mon Sep 17 00:00:00 2001 From: chendejin Date: Tue, 7 May 2024 19:35:22 +0800 Subject: [PATCH] Fix crash for eps32 commissioner if ble disconnect during commissioning --- src/platform/ESP32/nimble/BLEManagerImpl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index b5d9e662b9706c..54219bfa4d84e6 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -503,6 +503,10 @@ bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const uint8_t value[2]; int rc; struct peer * peer = peer_find(conId); + if (peer == nullptr) + { + return false; + } dsc = peer_dsc_find_uuid(peer, (ble_uuid_t *) (&ShortUUID_CHIPoBLEService), (ble_uuid_t *) (&UUID_CHIPoBLEChar_TX), (ble_uuid_t *) (&ShortUUID_CHIPoBLE_CharTx_Desc)); @@ -537,6 +541,10 @@ bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, cons uint8_t value[2]; int rc; struct peer * peer = peer_find(conId); + if (peer == nullptr) + { + return false; + } dsc = peer_dsc_find_uuid(peer, (ble_uuid_t *) (&ShortUUID_CHIPoBLEService), (ble_uuid_t *) (&UUID_CHIPoBLEChar_TX), (ble_uuid_t *) (&ShortUUID_CHIPoBLE_CharTx_Desc));