The file opened in fip_read_image_from_file() is never closed in the error paths. Add the missing close() and while at it free the allocated pointer as well. Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- lib/fip.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fip.c b/lib/fip.c index 23e82098da..99d6c5c383 100644 --- a/lib/fip.c +++ b/lib/fip.c @@ -284,7 +284,7 @@ int fip_parse(struct fip_state *fip, static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char *filename) { struct stat st; - struct fip_image *image; + struct fip_image *image = NULL; int fd; ASSERT(uuid != NULL); @@ -298,7 +298,7 @@ static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char if (fstat(fd, &st) == -1) { pr_err("fstat %s: %m\n", filename); - return NULL; + goto err; } image = xzalloc(sizeof(*image)); @@ -306,12 +306,18 @@ static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char image->buffer = xmalloc(st.st_size); if (read_full(fd, image->buffer, st.st_size) != st.st_size) { pr_err("Failed to read %s: %m\n", filename); - return NULL; + goto err; } image->toc_e.size = st.st_size; close(fd); return image; + +err: + close(fd); + free(image); + + return NULL; } int fip_pack_images(struct fip_state *fip, -- 2.39.5