[PATCH v2 04/11] efi_loader: fix open_file_system() memory leak on fallback path

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sun Jun 21 10:19:08 CEST 2026


In dtbdump.c and smbiosdump.c, open_file_system() falls back to
locating the UEFI system partition via locate_handle_buffer() when
the loaded image's own partition does not expose the simple file
system protocol. The handle buffer returned by locate_handle_buffer()
must be freed via free_pool().

The guard condition read 'if (handle)' (checking the image handle,
which is never NULL) instead of 'if (handle_buffer)', so the buffer
was freed unconditionally even when locate_handle_buffer() was never
called and handle_buffer remained NULL, and it also obscured the
intent. Change the condition to 'if (handle_buffer)'.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
v2:
	new patch
---
 lib/efi_loader/dtbdump.c    | 2 +-
 lib/efi_loader/smbiosdump.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/efi_loader/dtbdump.c b/lib/efi_loader/dtbdump.c
index 1e72404ecc1..865edc33a97 100644
--- a/lib/efi_loader/dtbdump.c
+++ b/lib/efi_loader/dtbdump.c
@@ -350,7 +350,7 @@ open_file_system(struct efi_simple_file_system_protocol **file_system)
 					EFI_OPEN_PROTOCOL_GET_PROTOCOL);
 	if (ret != EFI_SUCCESS)
 		error(u"Failed to open simple file system protocol\r\n");
-	if (handle)
+	if (handle_buffer)
 		bs->free_pool(handle_buffer);
 
 	return ret;
diff --git a/lib/efi_loader/smbiosdump.c b/lib/efi_loader/smbiosdump.c
index 974728a43af..494c3d18945 100644
--- a/lib/efi_loader/smbiosdump.c
+++ b/lib/efi_loader/smbiosdump.c
@@ -248,7 +248,7 @@ open_file_system(struct efi_simple_file_system_protocol **file_system)
 					EFI_OPEN_PROTOCOL_GET_PROTOCOL);
 	if (ret != EFI_SUCCESS)
 		error(u"Failed to open simple file system protocol\r\n");
-	if (handle)
+	if (handle_buffer)
 		bs->free_pool(handle_buffer);
 
 	return ret;
-- 
2.53.0



More information about the U-Boot mailing list