[PATCH] tools: Fix memory and descriptor leak

ant.v.moryakov at gmail.com ant.v.moryakov at gmail.com
Fri Apr 18 10:19:56 CEST 2025


From: Maks Mishin <maks.mishinFZ at gmail.com>

Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
---
 tools/zynqmpbif.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c
index 82ce0ac1..76b7a35f 100644
--- a/tools/zynqmpbif.c
+++ b/tools/zynqmpbif.c
@@ -226,8 +226,10 @@ static char *read_full_file(const char *filename, size_t *size)
 	bufp = buf;
 	while (len < sbuf.st_size) {
 		r = read(fd, bufp, sbuf.st_size - len);
-		if (r < 0)
+		if (r < 0) {
+			free(buf);
 			return NULL;
+		}
 		len += r;
 		bufp += r;
 	}
@@ -793,6 +795,8 @@ static const struct bif_file_type *get_file_type(struct bif_entry *entry)
 
 	if (read(fd, &header, sizeof(header)) != sizeof(header)) {
 		printf("Error reading file %s", entry->filename);
+		if (fd)
+			close(fd);
 		return NULL;
 	}
 
-- 
2.34.1


More information about the U-Boot mailing list