Skip to contentSkip to conversation

UEFI: Fix several memory leaks of UEFI handles

PATCH RESEND Superseded Khalid Ali 1 participant 1 message Jul 10, 2025

lore
Share & tools
lore

Khalid Ali

author
#0 lore raw

PATCH RESEND 1/1 UEFI: Fix several memory leaks of UEFI handles

Fix possible and absolute memory leaks of "handles" returned by grub_efi_locate_handle() using grub_malloc().

---
 grub-core/commands/efi/lsefi.c | 1 +
 grub-core/commands/efi/tpm.c   | 2 ++
 grub-core/term/efi/serial.c    | 4 ++--
 grub-core/video/efi_gop.c      | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)
grub-core/commands/efi/lsefi.c +1 -0
index 7b8316d41..f4c10392d 100644
@@ -129,6 +129,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
 
     }
 
+  grub_free (handles);
   return 0;
 }
 
grub-core/commands/efi/tpm.c +2 -0
index cbac69866..cb39b7bba 100644
@@ -112,6 +112,7 @@ grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
       grub_tpm_version = 1;
       *protocol_version = 1;
       grub_dprintf ("tpm", "TPM handle Found, version: 1\n");
+      grub_free (handles);
       return 1;
     }
 
@@ -124,6 +125,7 @@ grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
       grub_tpm_version = 2;
       *protocol_version = 2;
       grub_dprintf ("tpm", "TPM handle Found, version: 2\n");
+      grub_free (handles);
       return 1;
     }
 
grub-core/term/efi/serial.c +2 -2
index 5dfd2d86c..e409b8d5e 100644
@@ -169,13 +169,13 @@ grub_efiserial_init (void)
 
       port = grub_zalloc (sizeof (*port));
       if (!port)
-	return;
+	break;
 
       port->name = grub_malloc (sizeof ("efiXXXXXXXXXXXXXXXXXXXX"));
       if (!port->name)
 	{
 	  grub_free (port);
-	  return;
+	  break;
 	}
       grub_snprintf (port->name, sizeof ("efiXXXXXXXXXXXXXXXXXXXX"),
 		     "efi%d", num_serial++);
grub-core/video/efi_gop.c +1 -1
index 9452f5e58..1ad2e709d 100644
@@ -94,7 +94,7 @@ check_protocol (void)
   gop_handle = 0;
 
   grub_dprintf ("video", "GOP: no usable mode\n");
-
+  grub_free (handles);
   return 0;
 }
 
Signature · 7 lines
2.49.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel