From efd3dbecfb1bfbfc27a79ce8b6bb23300ae5a3d0 Mon Sep 17 00:00:00 2001 From: Rapsssito Date: Mon, 19 Aug 2024 17:15:18 +0200 Subject: [PATCH] Add service and server null checks for notify --- esphome/components/esp32_ble_server/ble_characteristic.cpp | 3 ++- esphome/components/esp32_ble_server/ble_characteristic.h | 2 +- esphome/components/esp32_ble_server/ble_service.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/esp32_ble_server/ble_characteristic.cpp b/esphome/components/esp32_ble_server/ble_characteristic.cpp index 3d0f615618..5ec74c2b47 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.cpp +++ b/esphome/components/esp32_ble_server/ble_characteristic.cpp @@ -45,7 +45,8 @@ void BLECharacteristic::notify(bool require_ack) { ESP_LOGW(TAG, "require_ack=true is not yet supported (i.e. INDICATE is not yet supported)"); // TODO: Handle when require_ack=true } - if (this->service_->get_server()->get_connected_client_count() == 0) + if (this->service_ == nullptr || this->service_->get_server() == nullptr || + this->service_->get_server()->get_connected_client_count() == 0) return; for (auto &client : this->service_->get_server()->get_clients()) { diff --git a/esphome/components/esp32_ble_server/ble_characteristic.h b/esphome/components/esp32_ble_server/ble_characteristic.h index 4eb8673f74..03d6c5034e 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.h +++ b/esphome/components/esp32_ble_server/ble_characteristic.h @@ -74,7 +74,7 @@ class BLECharacteristic : public EventEmitter characteristics_; BLECharacteristic *last_created_characteristic_{nullptr}; uint32_t created_characteristic_count_{0}; - BLEServer *server_; + BLEServer *server_ = nullptr; ESPBTUUID uuid_; uint16_t num_handles_; uint16_t handle_{0xFFFF};