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>
/* 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: