[image] Use image replacement when executing extracted images

Use image_replace() to transfer execution to the extracted image,
rather than calling image_exec() directly.  This allows the original
archive image to be freed immediately if it was marked as an
automatically freeable image (e.g. via "chain --autofree").

In particular, this ensures that in the case of an archive image
containing another archive image (such as an EFI zboot kernel wrapper
image containing a gzip-compressed kernel image), the intermediate
extracted image will be freed as early as possible, since extracted
images are always marked as automatically freeable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-05-20 15:27:49 +01:00
parent e2f4dba2b7
commit d15a11f3a4

View File

@@ -119,9 +119,14 @@ int image_extract_exec ( struct image *image ) {
/* Set auto-unregister flag */
extracted->flags |= IMAGE_AUTO_UNREGISTER;
/* Tail-recurse into extracted image */
return image_exec ( extracted );
/* Replace current image */
if ( ( rc = image_replace ( extracted ) ) != 0 )
goto err_replace;
/* Return to allow replacement image to be executed */
return 0;
err_replace:
err_set_cmdline:
unregister_image ( extracted );
err_extract: