1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-05 11:23:47 +01:00
This commit is contained in:
J. Nick Koston
2025-06-11 13:05:01 -05:00
parent 55ee0b116d
commit dc47faa4b6

View File

@@ -46,6 +46,10 @@ class BLEEvent {
this->type_ = GAP; this->type_ = GAP;
this->event_.gap.gap_event = e; this->event_.gap.gap_event = e;
if (p == nullptr) {
return; // Invalid event, but we can't log in header file
}
// Only copy the data we actually use for each GAP event type // Only copy the data we actually use for each GAP event type
switch (e) { switch (e) {
case ESP_GAP_BLE_SCAN_RESULT_EVT: case ESP_GAP_BLE_SCAN_RESULT_EVT:
@@ -85,6 +89,12 @@ class BLEEvent {
this->event_.gattc.gattc_event = e; this->event_.gattc.gattc_event = e;
this->event_.gattc.gattc_if = i; this->event_.gattc.gattc_if = i;
if (p == nullptr) {
this->event_.gattc.gattc_param = nullptr;
this->event_.gattc.data = nullptr;
return; // Invalid event, but we can't log in header file
}
// Heap-allocate param and data // Heap-allocate param and data
// Heap allocation is used because GATTC/GATTS events are rare (<1% of events) // Heap allocation is used because GATTC/GATTS events are rare (<1% of events)
// while GAP events (99%) are stored inline to minimize memory usage // while GAP events (99%) are stored inline to minimize memory usage
@@ -114,6 +124,12 @@ class BLEEvent {
this->event_.gatts.gatts_event = e; this->event_.gatts.gatts_event = e;
this->event_.gatts.gatts_if = i; this->event_.gatts.gatts_if = i;
if (p == nullptr) {
this->event_.gatts.gatts_param = nullptr;
this->event_.gatts.data = nullptr;
return; // Invalid event, but we can't log in header file
}
// Heap-allocate param and data // Heap-allocate param and data
// Heap allocation is used because GATTC/GATTS events are rare (<1% of events) // Heap allocation is used because GATTC/GATTS events are rare (<1% of events)
// while GAP events (99%) are stored inline to minimize memory usage // while GAP events (99%) are stored inline to minimize memory usage