loader/i386/pc/linux: Fix resource leak

In grub_cmd_initrd(), memory is allocated for variable initrd_ctx
before calling grub_relocator_alloc_chunk_align_safe(). When the
function call fails, initrd_ctx should be freed before exiting
grub_cmd_initrd().

Fixes: CID 473852

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Lidong Chen 2025-06-23 17:46:01 +00:00 committed by Daniel Kiper
parent de80acf368
commit a68a7dece4

View File

@ -457,7 +457,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
err = grub_relocator_alloc_chunk_align_safe (relocator, &ch, addr_min, addr_max, size,
0x1000, GRUB_RELOCATOR_PREFERENCE_HIGH, 0);
if (err)
return err;
goto fail;
initrd_chunk = get_virtual_current_address (ch);
initrd_addr = get_physical_target_address (ch);
}