image: close images on error paths

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrey Vagin 2015-01-22 18:56:03 +03:00 committed by Pavel Emelyanov
parent b99fbf66fb
commit f67fa36ce5
2 changed files with 8 additions and 5 deletions

2
bfd.c
View file

@ -125,7 +125,7 @@ void bclose(struct bfd *f)
buf_put(&f->b);
}
close(f->fd);
close_safe(&f->fd);
}
static int brefill(struct bfd *f)

11
image.c
View file

@ -236,7 +236,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
if (oflags & O_NOBUF)
bfd_setraw(&img->_x);
else if (bfdopen(&img->_x, flags))
goto err;
goto err_close;
if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
goto skip_magic;
@ -245,14 +245,14 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
u32 magic;
if (read_img(img, &magic) < 0)
goto err;
goto err_close;
if (magic != imgset_template[type].magic) {
pr_err("Magic doesn't match for %s\n", path);
goto err;
goto err_close;
}
} else {
if (write_img(img, &imgset_template[type].magic))
goto err;
goto err_close;
}
skip_magic:
@ -262,6 +262,9 @@ err:
xfree(img);
errn:
return NULL;
err_close:
close_image(img);
return NULL;
}
void close_image(struct cr_img *img)