[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:
Jonathan Hui
2026-04-09 17:52:29 -05:00
committed by GitHub
parent dbbadb4021
commit fc3ffa7a69
+12 -1
View File
@@ -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)
{