From: ant.v.moryakov@gmail.com
To: u-boot@lists.denx.de
Cc: Maks Mishin <maks.mishinFZ@gmail.com>,
Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH] tools: Fix memory and descriptor leak
Date: Fri, 18 Apr 2025 21:21:31 +0300 [thread overview]
Message-ID: <20250418182131.190511-1-ant.v.moryakov@gmail.com> (raw)
From: Maks Mishin <maks.mishinFZ@gmail.com>
Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
tools/zynqmpbif.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/zynqmpbif.c b/tools/zynqmpbif.c
index 82ce0ac1a52..33c68eac9f3 100644
--- a/tools/zynqmpbif.c
+++ b/tools/zynqmpbif.c
@@ -205,7 +205,7 @@ static const struct bif_flags bif_flags[] = {
static char *read_full_file(const char *filename, size_t *size)
{
- char *buf, *bufp;
+ char *buf = NULL, *bufp;
struct stat sbuf;
int len = 0, r, fd;
@@ -214,24 +214,28 @@ static char *read_full_file(const char *filename, size_t *size)
return NULL;
if (fstat(fd, &sbuf) < 0)
- return NULL;
+ goto out;
if (size)
*size = sbuf.st_size;
buf = malloc(sbuf.st_size);
if (!buf)
- return NULL;
+ goto out;
bufp = buf;
while (len < sbuf.st_size) {
r = read(fd, bufp, sbuf.st_size - len);
- if (r < 0)
- return NULL;
+ if (r < 0) {
+ free(buf);
+ buf = NULL;
+ goto out;
+ }
len += r;
bufp += r;
}
+out:
close(fd);
return buf;
--
2.30.2
next reply other threads:[~2025-04-18 18:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 18:21 ant.v.moryakov [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-04-18 8:19 [PATCH] scripts: Fix potential null-deref ant.v.moryakov
2025-04-18 8:19 ` [PATCH] tools: Fix memory and descriptor leak ant.v.moryakov
2025-04-18 13:51 ` Quentin Schulz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250418182131.190511-1-ant.v.moryakov@gmail.com \
--to=ant.v.moryakov@gmail.com \
--cc=maks.mishinFZ@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.