diff --git a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp index 58cd98bd..8b19e2da 100644 --- a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp @@ -151,11 +151,13 @@ namespace hal auto gattCompleteEvent = *reinterpret_cast(vendorEvent->data); - really_assert(gattCompleteEvent.Connection_Handle == connectionContext.connectionHandle); - really_assert(gattCompleteEvent.Error_Code == BLE_STATUS_SUCCESS); + auto localOnConnection = std::exchange(onConnection, nullptr); - if (onConnection) - infra::Subject::NotifyObservers(std::exchange(onConnection, nullptr)); + if (localOnConnection && gattCompleteEvent.Error_Code == BLE_STATUS_SUCCESS) + { + really_assert(gattCompleteEvent.Connection_Handle == connectionContext.connectionHandle); + infra::Subject::NotifyObservers(localOnConnection); + } } void GapCentralSt::HandleL2capConnectionUpdateRequestEvent(evt_blecore_aci* vendorEvent)