diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index 16b46cf..60e7db2 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -468,10 +468,15 @@ NimBLEScanResults NimBLEScan::getResults() { * @brief Clear the stored results of the scan. */ void NimBLEScan::clearResults() { - for (const auto& dev : m_scanResults.m_deviceVec) { - delete dev; + if (m_scanResults.m_deviceVec.size()) { + std::vector vSwap{}; + ble_npl_hw_enter_critical(); + vSwap.swap(m_scanResults.m_deviceVec); + ble_npl_hw_exit_critical(0); + for (const auto& dev : vSwap) { + delete dev; + } } - std::vector().swap(m_scanResults.m_deviceVec); } // clearResults /**