From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Sun, 30 Jul 2023 10:59:32 +0000 (+0200)
Subject: efi_loader: memory leak efi_add_memory_map_pg
X-Git-Tag: v2025.01-rc5-pxa1908~902^2~3
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/%7B%7B%20%24.Site.BaseURL%20%7D%7Dposts/%7B%7B%20%28.OutputFormats.Get?a=commitdiff_plain;h=ecae4bbf35fac3cde0c41c012a05c8e5b4ade90f;p=u-boot.git

efi_loader: memory leak efi_add_memory_map_pg

Don't leak newlist if we error out.

Fixes: 74c16acce30b ("efi_loader: Don't allocate from memory holes")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 45d3bf52b8..ebf4a2d5fa 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -324,6 +324,7 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 pages,
 				 * The user requested to only have RAM overlaps,
 				 * but we hit a non-RAM region. Error out.
 				 */
+				free(newlist);
 				return EFI_NO_MAPPING;
 			case EFI_CARVE_NO_OVERLAP:
 				/* Just ignore this list entry */
@@ -354,6 +355,7 @@ static efi_status_t efi_add_memory_map_pg(u64 start, u64 pages,
 		 * The payload wanted to have RAM overlaps, but we overlapped
 		 * with an unallocated region. Error out.
 		 */
+		free(newlist);
 		return EFI_NO_MAPPING;
 	}