Fix potential exception when scan is restarted.

If the scan is restarted in NimBLEScan::start, there is a chance that a result from
the previous scan arrives and the device is deleted when the callback is called.
This change ignores any results that come when the scan has stopped.
This commit is contained in:
h2zero
2025-04-14 08:39:28 -06:00
parent 033c7c27ad
commit 856adebad5

View File

@ -54,6 +54,11 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
(void)arg;
NimBLEScan* pScan = NimBLEDevice::getScan();
if (!pScan->isScanning()) {
NIMBLE_LOGI(LOG_TAG, "Scan stopped, ignoring event");
return 0;
}
switch (event->type) {
case BLE_GAP_EVENT_EXT_DISC:
case BLE_GAP_EVENT_DISC: {