* [PATCH] fip: fix missing close() in error path
@ 2025-03-03 7:28 Sascha Hauer
0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2025-03-03 7:28 UTC (permalink / raw)
To: Barebox List
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@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-03-03 7:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03 7:28 [PATCH] fip: fix missing close() in error path Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox