Skip to content

Commit 0d3ad19

Browse files
visitorckwardbiesheuvel
authored andcommitted
efi: fix memory leak in krealloc failure handling
In the previous code, there was a memory leak issue where the previously allocated memory was not freed upon a failed krealloc operation. This patch addresses the problem by releasing the old memory before setting the pointer to NULL in case of a krealloc failure. This ensures that memory is properly managed and avoids potential memory leaks. Signed-off-by: Kuan-Wei Chiu <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent ff07186 commit 0d3ad19

File tree

1 file changed

+6
-2
lines changed
  • drivers/firmware/efi

1 file changed

+6
-2
lines changed

drivers/firmware/efi/efi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,13 @@ static __init int efivar_ssdt_load(void)
273273
if (status == EFI_NOT_FOUND) {
274274
break;
275275
} else if (status == EFI_BUFFER_TOO_SMALL) {
276-
name = krealloc(name, name_size, GFP_KERNEL);
277-
if (!name)
276+
efi_char16_t *name_tmp =
277+
krealloc(name, name_size, GFP_KERNEL);
278+
if (!name_tmp) {
279+
kfree(name);
278280
return -ENOMEM;
281+
}
282+
name = name_tmp;
279283
continue;
280284
}
281285

0 commit comments

Comments
 (0)