All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/1] tools/env: avoid memory leak in fw_setenv
Date: Sat, 15 Apr 2017 13:05:40 +0200	[thread overview]
Message-ID: <20170415110540.17036-1-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20170415105643.16884-1-xypron.glpk@gmx.de>

If realloc fails we should release the old buffer.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v2:
  Initial mail was garbled.
---
 tools/env/fw_env.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 862a0b1a02..31c18d73bc 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -469,6 +469,7 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 	int i;
 	size_t len;
 	char *name, **valv;
+	char *oldval;
 	char *value = NULL;
 	int valc;
 
@@ -500,11 +501,13 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 
 		if (value)
 			value[len - 1] = ' ';
+		oldval = value;
 		value = realloc(value, len + val_len + 1);
 		if (!value) {
 			fprintf(stderr,
 				"Cannot malloc %zu bytes: %s\n",
 				len, strerror(errno));
+			free(oldval);
 			return -1;
 		}
 
-- 
2.11.0

  reply	other threads:[~2017-04-15 11:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-15 10:56 [U-Boot] [PATCH 1/1] tools/env: avoid memory leak in fw_setenv Heinrich at lists.denx.de
2017-04-15 11:05 ` Heinrich Schuchardt [this message]
2017-04-15 16:11   ` [U-Boot] [PATCH v2 " Tom Rini
2017-04-16 19:34   ` Simon Glass
2017-04-19 13:03   ` [U-Boot] [U-Boot, v2, " Tom Rini

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=20170415110540.17036-1-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --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.