]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
tools: Fix freeing of image memory after cell creation
authorJan Kiszka <jan.kiszka@siemens.com>
Wed, 9 Apr 2014 16:35:44 +0000 (18:35 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Wed, 9 Apr 2014 17:07:08 +0000 (19:07 +0200)
Regression of 95666fd1: We are not allocating multiple images, and the
image variable does not point to a valid address when we try to free the
former only image at the end of cell_create. Properly loop over all the
images for freeing.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
tools/jailhouse.c

index 20246d5e27b01075383da52bbcd44c66d3f34468..00f801735f07df08815badb9df6b7f89870b2327 100644 (file)
@@ -110,7 +110,7 @@ static int cell_create(int argc, char *argv[])
 {
        struct jailhouse_preload_image *image;
        struct jailhouse_new_cell *cell;
-       unsigned int images, arg_num;
+       unsigned int images, arg_num, n;
        size_t size;
        int err, fd;
        char *endp;
@@ -146,9 +146,8 @@ static int cell_create(int argc, char *argv[])
        cell->num_preload_images = images;
 
        arg_num = 4;
-       image = cell->image;
 
-       while (images > 0) {
+       for (n = 0, image = cell->image; n < images; n++, image++) {
                image->source_address =
                        (unsigned long)read_file(argv[arg_num++], &size);
                image->size = size;
@@ -165,7 +164,6 @@ static int cell_create(int argc, char *argv[])
                        arg_num += 2;
                }
                image++;
-               images--;
        }
 
        fd = open_dev();
@@ -176,7 +174,8 @@ static int cell_create(int argc, char *argv[])
 
        close(fd);
        free((void *)(unsigned long)cell->config_address);
-       free((void *)(unsigned long)image->source_address);
+       for (n = 0, image = cell->image; n < images; n++, image++)
+               free((void *)(unsigned long)image->source_address);
        free(cell);
 
        return err;