From 09297fb72aced36cf5595b634cfc676dc214ecd1 Mon Sep 17 00:00:00 2001 From: thekurtovic <40248206+thekurtovic@users.noreply.github.com> Date: Wed, 25 Dec 2024 10:17:50 -0500 Subject: [PATCH] NimBLEScan increment m_callbackSent before callback. Fixes heap corruption observed on CONFIG_HEAP_POISONING_COMPREHENSIVE. --- src/NimBLEScan.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index 61af025..8abaf01 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -119,19 +119,19 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) { } if (!advertisedDevice->m_callbackSent) { - pScan->m_pScanCallbacks->onDiscovered(advertisedDevice); advertisedDevice->m_callbackSent++; + pScan->m_pScanCallbacks->onDiscovered(advertisedDevice); } // If not active scanning or scan response is not available // or extended advertisement scanning, report the result to the callback now. if (pScan->m_scanParams.passive || !isLegacyAdv || !advertisedDevice->isScannable()) { - pScan->m_pScanCallbacks->onResult(advertisedDevice); advertisedDevice->m_callbackSent++; + pScan->m_pScanCallbacks->onResult(advertisedDevice); } else if (isLegacyAdv && event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) { + advertisedDevice->m_callbackSent++; // got the scan response report the full data. pScan->m_pScanCallbacks->onResult(advertisedDevice); - advertisedDevice->m_callbackSent++; } // If not storing results and we have invoked the callback, delete the device.