Skip to content

Commit 856adeb

Browse files
committed
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.
1 parent 033c7c2 commit 856adeb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/NimBLEScan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
5454
(void)arg;
5555
NimBLEScan* pScan = NimBLEDevice::getScan();
5656

57+
if (!pScan->isScanning()) {
58+
NIMBLE_LOGI(LOG_TAG, "Scan stopped, ignoring event");
59+
return 0;
60+
}
61+
5762
switch (event->type) {
5863
case BLE_GAP_EVENT_EXT_DISC:
5964
case BLE_GAP_EVENT_DISC: {

0 commit comments

Comments
 (0)