mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Ulrich Ölmann" <u.oelmann@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] imd: fix memory leak
Date: Mon, 16 Sep 2019 10:27:01 +0200	[thread overview]
Message-ID: <20190916082701.27350-1-u.oelmann@pengutronix.de> (raw)

Each invocation of 'imd' ate up to 1MB of RAM.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
---
 common/imd.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/common/imd.c b/common/imd.c
index 05e118e77361..913a01de87bf 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -337,8 +337,10 @@ int imd_command(int argc, char *argv[])
 		return -errno;
 
 	imd_start = imd_get(buf, size);
-	if (IS_ERR(imd_start))
-		return PTR_ERR(imd_start);
+	if (IS_ERR(imd_start)) {
+		ret = PTR_ERR(imd_start);
+		goto out;
+	}
 
 	if (type == IMD_TYPE_INVALID) {
 		imd_for_each(imd_start, imd) {
@@ -356,7 +358,8 @@ int imd_command(int argc, char *argv[])
 		imd = imd_find_type(imd_start, type);
 		if (!imd) {
 			debug("No tag of type 0x%08x found\n", type);
-			return -ENODATA;
+			ret = -ENODATA;
+			goto out;
 		}
 
 		if (imd_is_string(type)) {
@@ -370,8 +373,10 @@ int imd_command(int argc, char *argv[])
 				str = imd_concat_strings(imd);
 			}
 
-			if (!str)
-				return -ENODATA;
+			if (!str) {
+				ret = -ENODATA;
+				goto out;
+			}
 
 			if (variable_name)
 				imd_command_setenv(variable_name, str);
@@ -384,5 +389,8 @@ int imd_command(int argc, char *argv[])
 		}
 	}
 
-	return 0;
+	ret = 0;
+out:
+	free(buf);
+	return ret;
 }
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2019-09-16  8:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16  8:27 Ulrich Ölmann [this message]
2019-09-17  9:49 ` 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=20190916082701.27350-1-u.oelmann@pengutronix.de \
    --to=u.oelmann@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