]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
loader/efi/linux: Unload previous Linux kernel/initrd before updating kernel size
authorAdriano Cordova <adrianox@gmail.com>
Wed, 18 Jun 2025 15:38:14 +0000 (11:38 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 26 Jun 2025 16:05:08 +0000 (18:05 +0200)
Unload previous Linux kernel/initrd before updating the global variable
kernel_size. Otherwise the previous Linux kernel gets deallocated with
the kernel_size of the Linux kernel that is being currently loaded.

Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/loader/efi/linux.c

index 7ca80635c31e3238c13032fd2994861e83c3af1b..36dea2931b146c64282e3fb729973a19e048250c 100644 (file)
@@ -492,6 +492,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (!file)
     goto fail;
 
+  grub_loader_unset();
+
   kernel_size = grub_file_size (file);
 
   if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE)
@@ -514,8 +516,6 @@ fallback:
     }
 #endif
 
-  grub_loader_unset();
-
   grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
   kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
   grub_dprintf ("linux", "kernel numpages: %lld\n",