From 58a697bed166c7540759432b1a74707aa3ea67ad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Jun 2025 15:07:23 +0200 Subject: [PATCH] cleanup --- esphome/components/esp32_ble/ble_event.h | 1 + esphome/components/esp32_ble/ble_event_pool.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/esphome/components/esp32_ble/ble_event.h b/esphome/components/esp32_ble/ble_event.h index f929c4662a..cb70d3e018 100644 --- a/esphome/components/esp32_ble/ble_event.h +++ b/esphome/components/esp32_ble/ble_event.h @@ -203,6 +203,7 @@ class BLEEvent { break; default: + // We only handle 4 GAP event types, others are dropped break; } } diff --git a/esphome/components/esp32_ble/ble_event_pool.h b/esphome/components/esp32_ble/ble_event_pool.h index df92c138c3..d118ccf3ab 100644 --- a/esphome/components/esp32_ble/ble_event_pool.h +++ b/esphome/components/esp32_ble/ble_event_pool.h @@ -42,14 +42,17 @@ template class BLEEventPool { RAMAllocator allocator(RAMAllocator::ALLOC_INTERNAL); event = allocator.allocate(1); - if (event != nullptr) { - // Placement new to construct the object - new (event) BLEEvent(); - this->total_created_++; + if (event == nullptr) { + // Memory allocation failed + return nullptr; } + + // Placement new to construct the object + new (event) BLEEvent(); + this->total_created_++; } - return event; // Will be nullptr if allocation failed + return event; } // Return an event to the pool