Skip to content

Commit 0f0899c

Browse files
khaliid2040Daniel Kiper
authored andcommitted
efi: Fix several memory leaks of UEFI handles
Fix possible and absolute memory leaks of "handles" returned by grub_efi_locate_handle() using grub_malloc(). Signed-off-by: Khalid Ali <khaliidcaliy@gmail.com> Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1 parent c477a95 commit 0f0899c

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

grub-core/commands/efi/lsefi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
129129

130130
}
131131

132+
grub_free (handles);
132133
return 0;
133134
}
134135

grub-core/commands/efi/tpm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
113113
grub_tpm_version = 1;
114114
*protocol_version = 1;
115115
grub_dprintf ("tpm", "TPM handle Found, version: 1\n");
116+
grub_free (handles);
116117
return 1;
117118
}
118119

@@ -125,6 +126,7 @@ grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
125126
grub_tpm_version = 2;
126127
*protocol_version = 2;
127128
grub_dprintf ("tpm", "TPM handle Found, version: 2\n");
129+
grub_free (handles);
128130
return 1;
129131
}
130132

grub-core/term/efi/serial.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ grub_efiserial_init (void)
169169

170170
port = grub_zalloc (sizeof (*port));
171171
if (!port)
172-
return;
172+
break;
173173

174174
port->name = grub_malloc (sizeof ("efiXXXXXXXXXXXXXXXXXXXX"));
175175
if (!port->name)
176176
{
177177
grub_free (port);
178-
return;
178+
break;
179179
}
180180
grub_snprintf (port->name, sizeof ("efiXXXXXXXXXXXXXXXXXXXX"),
181181
"efi%d", num_serial++);

grub-core/video/efi_gop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ check_protocol (void)
9494
gop_handle = 0;
9595

9696
grub_dprintf ("video", "GOP: no usable mode\n");
97-
97+
grub_free (handles);
9898
return 0;
9999
}
100100

0 commit comments

Comments
 (0)