mirror of
https://github.com/espressif/openthread.git
synced 2026-08-26 20:19:53 +00:00
[nexus] fix segmentation fault during Core destruction (#12866)
When the Nexus test finishes, it automatically destructs all its allocated Nodes sequentially. During this destruction phase, the OpenThread instance attempts to destruct objects like `Nat64::Translator`, which might in turn call logging mechanisms like `Mapping::Free()` that rely on the static `Instance::GetActiveInstance()` pointer. Because `Core::~Core()` did not maintain or update `gActiveInstance` while iterating through node destructors, this pointer was left dangling, causing segmentation faults when dereferenced by `ot::Instance::GetLogLevel()`. This commit fixes `Core::~Core()` to manually loop through and destruct the `mNodes` list, calling `UpdateActiveInstance(&node->GetInstance())` right before destroying each node. This ensures that `gActiveInstance` points to the correct context while node destruction logic runs.
This commit is contained in:
@@ -331,8 +331,19 @@ void Core::AddOmrPrefixTestVar(const char *aName, Node &aNode)
|
||||
OT_UNUSED_VARIABLE(aNode);
|
||||
#endif
|
||||
}
|
||||
Core::~Core(void)
|
||||
{
|
||||
while (!mNodes.IsEmpty())
|
||||
{
|
||||
Node *node = mNodes.GetHead();
|
||||
|
||||
Core::~Core(void) { sInUse = false; }
|
||||
UpdateActiveInstance(&node->GetInstance());
|
||||
mNodes.Pop();
|
||||
}
|
||||
|
||||
UpdateActiveInstance(nullptr);
|
||||
sInUse = false;
|
||||
}
|
||||
|
||||
Node &Core::CreateNode(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user