Commit f67fa36c authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

image: close images on error paths

Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b99fbf66
...@@ -125,7 +125,7 @@ void bclose(struct bfd *f) ...@@ -125,7 +125,7 @@ void bclose(struct bfd *f)
buf_put(&f->b); buf_put(&f->b);
} }
close(f->fd); close_safe(&f->fd);
} }
static int brefill(struct bfd *f) static int brefill(struct bfd *f)
......
...@@ -236,7 +236,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...) ...@@ -236,7 +236,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
if (oflags & O_NOBUF) if (oflags & O_NOBUF)
bfd_setraw(&img->_x); bfd_setraw(&img->_x);
else if (bfdopen(&img->_x, flags)) else if (bfdopen(&img->_x, flags))
goto err; goto err_close;
if (imgset_template[type].magic == RAW_IMAGE_MAGIC) if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
goto skip_magic; goto skip_magic;
...@@ -245,14 +245,14 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...) ...@@ -245,14 +245,14 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
u32 magic; u32 magic;
if (read_img(img, &magic) < 0) if (read_img(img, &magic) < 0)
goto err; goto err_close;
if (magic != imgset_template[type].magic) { if (magic != imgset_template[type].magic) {
pr_err("Magic doesn't match for %s\n", path); pr_err("Magic doesn't match for %s\n", path);
goto err; goto err_close;
} }
} else { } else {
if (write_img(img, &imgset_template[type].magic)) if (write_img(img, &imgset_template[type].magic))
goto err; goto err_close;
} }
skip_magic: skip_magic:
...@@ -262,6 +262,9 @@ err: ...@@ -262,6 +262,9 @@ err:
xfree(img); xfree(img);
errn: errn:
return NULL; return NULL;
err_close:
close_image(img);
return NULL;
} }
void close_image(struct cr_img *img) void close_image(struct cr_img *img)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment