mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] scripts: common: fix buffer freeing
Date: Tue, 17 Oct 2023 23:36:06 +0200	[thread overview]
Message-ID: <20231017213608.3494255-3-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20231017213608.3494255-1-m.felsch@pengutronix.de>

We pass the wrong address to free in case of an error occured in
preceding while-read loop if the loop is executed more than once. Fix
this by use the outbuf which stores the original malloc'ed address.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 scripts/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/common.c b/scripts/common.c
index 0599cd41ff..49c468a1ea 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -76,8 +76,8 @@ int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_si
 	ret = 0;
 	goto close;
 free:
+	free(*outbuf);
 	*outbuf = NULL;
-	free(buf);
 close:
 	close(fd);
 	return ret;
-- 
2.41.0




  parent reply	other threads:[~2023-10-17 21:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 21:36 [PATCH 0/4] i.MX USB Loader Windows Fixes Marco Felsch
2023-10-17 21:36 ` [PATCH 1/4] scripts: common: fix read_file_2 for windows Marco Felsch
2023-10-17 21:36 ` Marco Felsch [this message]
2023-10-17 21:36 ` [PATCH 3/4] usb: gadget: fsl_udc: lower state_complete constraints Marco Felsch
2023-10-17 21:36 ` [PATCH 4/4] imx-usb-loader: fix windows usage Marco Felsch
2023-10-18 10:46   ` Ahmad Fatoum
2023-10-18 12:53     ` Marco Felsch
2023-10-18 13:07       ` Ahmad Fatoum
2023-10-18 14:32         ` Marco Felsch
2023-10-18  8:18 ` [PATCH 0/4] i.MX USB Loader Windows Fixes Sascha Hauer

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=20231017213608.3494255-3-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox