[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:
Abtin Keshavarzian
2026-02-07 18:59:13 -08:00
committed by GitHub
parent c0090877ae
commit 52bd082596
+1 -6
View File
@@ -358,17 +358,12 @@ Error Joiner::PrepareJoinerFinalizeMessage(const char *aProvisioningUrl,
}
exit:
if (error != kErrorNone)
{
FreeJoinerFinalizeMessage();
}
return error;
}
void Joiner::FreeJoinerFinalizeMessage(void)
{
VerifyOrExit(mState == kStateIdle && mFinalizeMessage != nullptr);
VerifyOrExit(mFinalizeMessage != nullptr);
mFinalizeMessage->Free();
mFinalizeMessage = nullptr;