From: Michael Brown Date: Tue, 20 May 2025 14:27:49 +0000 (+0100) Subject: [image] Use image replacement when executing extracted images X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=d15a11f3a4f49999447e9bd0c499455d1d9ef078;p=thirdparty%2Fipxe.git [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 --- diff --git a/src/core/archive.c b/src/core/archive.c index 3d3f00cc6..8b6accc6a 100644 --- a/src/core/archive.c +++ b/src/core/archive.c @@ -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: