summaryrefslogtreecommitdiff
path: root/tools/fdtgrep.c
diff options
context:
space:
mode:
authorMikhail Ilin <ilin.mikhail.ol@gmail.com>2022-11-23 14:31:03 +0300
committerTom Rini <trini@konsulko.com>2022-12-08 17:29:02 +0300
commit4b95e8407eba6e6fd73341695de15dec19e723a8 (patch)
treeaf689d28aa1eacaa60ac8d0d9748a2f37f7dd981 /tools/fdtgrep.c
parent17f8a7487689ad727aadc00c14cd3315cd880e4a (diff)
downloadu-boot-4b95e8407eba6e6fd73341695de15dec19e723a8.tar.xz
tools: fdtgrep: Fix handle leak
The handle "fd" was created in fdtgrep.c:708 by calling the "open" function and is lost in fdtgrep.c:716 and fdtgrep.c:723. Close file descriptor 'fd' before exiting with an error from function utilfdt_read_err_len(const char *filename, char **buffp, off_t *len). Fixes: 1043d0a0296a ("fdt: Add fdtgrep tool") Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/fdtgrep.c')
-rw-r--r--tools/fdtgrep.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
index 641d6a2e3e..7eabcab439 100644
--- a/tools/fdtgrep.c
+++ b/tools/fdtgrep.c
@@ -712,15 +712,19 @@ int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
/* Loop until we have read everything */
buf = malloc(bufsize);
- if (!buf)
+ if (!buf) {
+ close(fd);
return -ENOMEM;
+ }
do {
/* Expand the buffer to hold the next chunk */
if (offset == bufsize) {
bufsize *= 2;
buf = realloc(buf, bufsize);
- if (!buf)
+ if (!buf) {
+ close(fd);
return -ENOMEM;
+ }
}
ret = read(fd, &buf[offset], bufsize - offset);