Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,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();
Expand All @@ -930,36 +960,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

Expand Down Expand Up @@ -1240,4 +1240,4 @@ void nimble_cpp_assert(const char *file, unsigned line) {
}
#endif // CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED

#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BT_ENABLED