[PATCH 8/8] efi: Avoid a memory leak in efi_bind_block() on error path

Simon Glass sjg at chromium.org
Mon Dec 9 17:28:01 CET 2024


Free the memory used if an error occurs.

Signed-off-by: Simon Glass <sjg at chromium.org>
Suggested-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
---

 lib/efi/efi_app_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/efi/efi_app_init.c b/lib/efi/efi_app_init.c
index cc91e1d74b8..fec3f348cfb 100644
--- a/lib/efi/efi_app_init.c
+++ b/lib/efi/efi_app_init.c
@@ -60,8 +60,10 @@ int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
 	plat->handle = handle;
 	plat->blkio = blkio;
 	plat->device_path = malloc(device_path_len);
-	if (!plat->device_path)
+	if (!plat->device_path) {
+		free(plat);
 		return log_msg_ret("path", -ENOMEM);
+	}
 	memcpy(plat->device_path, device_path, device_path_len);
 	ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
 			  plat, ofnode_null(), &dev);
-- 
2.34.1



More information about the U-Boot mailing list