mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-09-23 06:41:36 +02:00
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>
This commit is contained in:
parent
17f8a74876
commit
4b95e8407e
@ -712,16 +712,20 @@ int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
|
|||||||
|
|
||||||
/* Loop until we have read everything */
|
/* Loop until we have read everything */
|
||||||
buf = malloc(bufsize);
|
buf = malloc(bufsize);
|
||||||
if (!buf)
|
if (!buf) {
|
||||||
|
close(fd);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
/* Expand the buffer to hold the next chunk */
|
/* Expand the buffer to hold the next chunk */
|
||||||
if (offset == bufsize) {
|
if (offset == bufsize) {
|
||||||
bufsize *= 2;
|
bufsize *= 2;
|
||||||
buf = realloc(buf, bufsize);
|
buf = realloc(buf, bufsize);
|
||||||
if (!buf)
|
if (!buf) {
|
||||||
|
close(fd);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = read(fd, &buf[offset], bufsize - offset);
|
ret = read(fd, &buf[offset], bufsize - offset);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user