From 624634371ee11d9e34bb3a28ab2089dc99c00b29 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 2 Mar 2026 10:05:38 -0800 Subject: [PATCH] [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. --- src/core/net/srp_server.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index aa8efb80a..a69790625 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -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(); }