]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[image] Use image replacement when executing extracted images
authorMichael Brown <mcb30@ipxe.org>
Tue, 20 May 2025 14:27:49 +0000 (15:27 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 20 May 2025 14:34:49 +0000 (15:34 +0100)
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>
src/core/archive.c

index 3d3f00cc6d0a9caf0f2cb7ccaa0284076936f4e9..8b6accc6a1a8b1cfdd5f4ef2ee8e577462b778a4 100644 (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: