8000 Fix potential exception when scan is restarted. · h2zero/NimBLE-Arduino@b6b91b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6b91b2

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 117ec4e commit b6b91b2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/NimBLEScan.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
5757
switch (event->type) {
5858
case BLE_GAP_EVENT_EXT_DISC:
5959
case BLE_GAP_EVENT_DISC: {
60+
if (!pScan->isScanning()) {
61+
NIMBLE_LOGI(LOG_TAG, "Scan stopped, ignoring event");
62+
return 0;
63+
}
64+
6065
# if CONFIG_BT_NIMBLE_EXT_ADV
6166
const auto& disc = event->ext_disc;
6267
const bool isLegacyAdv = disc.props & BLE_HCI_ADV_LEGACY_MASK;
@@ -483,11 +488,11 @@ void NimBLEScan::clearResults() {
483488
* @brief Dump the scan results to the log.
484489
*/
485490
void NimBLEScanResults::dump() const {
486-
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >=3
491+
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
487492
for (const auto& dev : m_deviceVec) {
488493
NIMBLE_LOGI(LOG_TAG, "- %s", dev->toString().c_str());
489494
}
490-
#endif
495+
# endif
491496
} // dump
492497

493498
/**

0 commit comments

Comments
 (0)
0