loader/efi/linux: Unload previous Linux kernel/initrd before updating kernel size

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>
This commit is contained in:
Adriano Cordova authored and Daniel Kiper committed 2025-06-26 18:05:08 +02:00
1 parent 249db11d8f
commit de80acf368
1 file changed
+2 -2
+2 -2
View File
@@ -492,6 +492,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (!file) if (!file)
goto fail; goto fail;
grub_loader_unset();
kernel_size = grub_file_size (file); kernel_size = grub_file_size (file);
if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE) if (grub_arch_efi_linux_load_image_header (file, &lh) != GRUB_ERR_NONE)
@@ -514,8 +516,6 @@ fallback:
} }
#endif #endif
grub_loader_unset();
grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); 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)); kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
grub_dprintf ("linux", "kernel numpages: %lld\n", grub_dprintf ("linux", "kernel numpages: %lld\n",