summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);