mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 07:07:47 +00:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user