[srp-server] fix possible aHost memory leak when granted lease is zero (#12587)

This commit fixes a potential memory leak of the allocated `aHost`
object in `Server::CommitSrpUpdate()`.

Previously, when the granted key lease was zero (indicating a request
to remove the host), the code used `VerifyOrExit(existingHost != nullptr)`
before calling `aHost.Free()`. If `existingHost` was null (e.g., when
receiving a request to remove a non-existent host), the function
would exit early and skip freeing `aHost`, causing a memory leak.

This is updated to always call `aHost.Free()` when `grantedKeyLease`
is zero, ensuring the memory is freed regardless of whether
`existingHost` is null or not.
This commit is contained in:
Abtin Keshavarzian
2026-03-02 12:05:38 -06:00
committed by GitHub
parent f23519e531
commit 624634371e
+5 -2
View File
@@ -629,8 +629,11 @@ void Server::CommitSrpUpdate(Error aError,
if (grantedKeyLease == 0)
{
VerifyOrExit(existingHost != nullptr);
LogInfo("Fully remove host %s", aHost.GetFullName());
if (existingHost != nullptr)
{
LogInfo("Fully remove host %s", aHost.GetFullName());
}
aHost.Free();
ExitNow();
}