summaryrefslogtreecommitdiffstats
path: root/src/arch/i386/interface/syslinux/comboot_call.c
diff options
context:
space:
mode:
authorMichael Brown2009-02-17 02:45:12 +0100
committerMichael Brown2009-02-17 02:45:12 +0100
commit14eafc5b8de58c4495087cddfefe89e03ccda70c (patch)
tree9538cfb2b84050d3416b1f100a6e29356cb3a95c /src/arch/i386/interface/syslinux/comboot_call.c
parent[comboot] Allow for tail recursion of COMBOOT images (diff)
downloadipxe-14eafc5b8de58c4495087cddfefe89e03ccda70c.tar.gz
ipxe-14eafc5b8de58c4495087cddfefe89e03ccda70c.tar.xz
ipxe-14eafc5b8de58c4495087cddfefe89e03ccda70c.zip
[comboot] Fix reference counting on replacement images
When chaining COMBOOT images, the old images now get freed correctly.
Diffstat (limited to 'src/arch/i386/interface/syslinux/comboot_call.c')
-rw-r--r--src/arch/i386/interface/syslinux/comboot_call.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/arch/i386/interface/syslinux/comboot_call.c b/src/arch/i386/interface/syslinux/comboot_call.c
index 02b2250b2..f37aa2ae1 100644
--- a/src/arch/i386/interface/syslinux/comboot_call.c
+++ b/src/arch/i386/interface/syslinux/comboot_call.c
@@ -157,7 +157,7 @@ void comboot_force_text_mode ( void ) {
* Fetch kernel and optional initrd
*/
static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
- struct image *kernel;
+ struct image *kernel = NULL;
struct image *initrd = NULL;
char *initrd_file;
int rc;
@@ -181,13 +181,13 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
if ( ! initrd ) {
DBG ( "COMBOOT: could not allocate initrd\n" );
rc = -ENOMEM;
- goto err_alloc_initrd;
+ goto out;
}
if ( ( rc = imgfetch ( initrd, initrd_file,
register_image ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch initrd: %s\n",
strerror ( rc ) );
- goto err_fetch_initrd;
+ goto out;
}
/* Restore space after initrd name, if applicable */
@@ -202,32 +202,31 @@ static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) {
if ( ! kernel ) {
DBG ( "COMBOOT: could not allocate kernel\n" );
rc = -ENOMEM;
- goto err_alloc_kernel;
+ goto out;
}
if ( ( rc = imgfetch ( kernel, kernel_file,
register_image ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch kernel: %s\n",
strerror ( rc ) );
- goto err_fetch_kernel;
+ goto out;
}
if ( ( rc = image_set_cmdline ( kernel, cmdline ) ) != 0 ) {
DBG ( "COMBOOT: could not set kernel command line: %s\n",
strerror ( rc ) );
- goto err_set_cmdline;
+ goto out;
}
/* Store kernel as replacement image */
- comboot_replacement_image = kernel;
-
- return 0;
-
- err_set_cmdline:
- err_fetch_kernel:
+ assert ( comboot_replacement_image == NULL );
+ comboot_replacement_image = image_get ( kernel );
+
+ out:
+ /* Drop image references unconditionally; either we want to
+ * discard them, or they have been registered and we should
+ * drop out local reference.
+ */
image_put ( kernel );
- err_alloc_kernel:
- err_fetch_initrd:
image_put ( initrd );
- err_alloc_initrd:
return rc;
}