mirror of
https://github.com/espressif/openthread.git
synced 2026-10-01 21:37:39 +00:00
[joiner] fix potential message leak when Start() fails (#12394)
This commit updates `FreeJoinerFinalizeMessage()` to remove the state check, allowing the message to be freed regardless of the current state. It also removes the redundant cleanup in `PrepareJoinerFinalizeMessage()` since `Joiner::Start()` handles the cleanup upon error. The `Joiner::Start()` method allocates the Joiner Finalize message and then transitions the state to `kStateDiscover` before starting the Seeker. If starting the Seeker fails, the exit label performs cleanup, including calling `FreeJoinerFinalizeMessage()`. Previously, `FreeJoinerFinalizeMessage()` checked that the state was `kStateIdle` before freeing the message. Since the state had already been updated to `kStateDiscover`, the message would not be freed, leading to a message leak on failure.
This commit is contained in:
@@ -358,17 +358,12 @@ Error Joiner::PrepareJoinerFinalizeMessage(const char *aProvisioningUrl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != kErrorNone)
|
|
||||||
{
|
|
||||||
FreeJoinerFinalizeMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joiner::FreeJoinerFinalizeMessage(void)
|
void Joiner::FreeJoinerFinalizeMessage(void)
|
||||||
{
|
{
|
||||||
VerifyOrExit(mState == kStateIdle && mFinalizeMessage != nullptr);
|
VerifyOrExit(mFinalizeMessage != nullptr);
|
||||||
|
|
||||||
mFinalizeMessage->Free();
|
mFinalizeMessage->Free();
|
||||||
mFinalizeMessage = nullptr;
|
mFinalizeMessage = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user