fix(NimBLEDevice): clear all before port_deinit to prevent crash

This commit is contained in:
William Emfinger 2024-09-06 08:52:04 -05:00 committed by h2zero
parent 91210b8610
commit 73f0277042

View file

@ -920,6 +920,36 @@ void NimBLEDevice::init(const std::string &deviceName) {
*/
/* STATIC */
void NimBLEDevice::deinit(bool clearAll) {
if(clearAll) {
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
if(NimBLEDevice::m_pServer != nullptr) {
delete NimBLEDevice::m_pServer;
NimBLEDevice::m_pServer = nullptr;
}
#endif
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
if(NimBLEDevice::m_bleAdvertising != nullptr) {
delete NimBLEDevice::m_bleAdvertising;
NimBLEDevice::m_bleAdvertising = nullptr;
}
#endif
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
if(NimBLEDevice::m_pScan != nullptr) {
delete NimBLEDevice::m_pScan;
NimBLEDevice::m_pScan= nullptr;
}
#endif
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
for(auto clt : m_pClients) {
deleteClient(clt);
}
#endif
m_ignoreList.clear();
}
int ret = nimble_port_stop();
if (ret == 0) {
nimble_port_deinit();
@ -933,36 +963,6 @@ void NimBLEDevice::deinit(bool clearAll) {
#endif
initialized = false;
m_synced = false;
if(clearAll) {
#if defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
if(NimBLEDevice::m_pServer != nullptr) {
delete NimBLEDevice::m_pServer;
NimBLEDevice::m_pServer = nullptr;
}
#endif
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
if(NimBLEDevice::m_bleAdvertising != nullptr) {
delete NimBLEDevice::m_bleAdvertising;
NimBLEDevice::m_bleAdvertising = nullptr;
}
#endif
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
if(NimBLEDevice::m_pScan != nullptr) {
delete NimBLEDevice::m_pScan;
NimBLEDevice::m_pScan= nullptr;
}
#endif
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
for(auto clt : m_pClients) {
deleteClient(clt);
}
#endif
m_ignoreList.clear();
}
}
} // deinit