From f67fa36ce5c46808e0dc658260bf1e84dc6c3242 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Thu, 22 Jan 2015 18:56:03 +0300 Subject: [PATCH] image: close images on error paths Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- bfd.c | 2 +- image.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bfd.c b/bfd.c index f89a9dffe..e4cccbb0b 100644 --- a/bfd.c +++ b/bfd.c @@ -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) diff --git a/image.c b/image.c index 36f726dae..e60cda74c 100644 --- a/image.c +++ b/image.c @@ -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)