aboutsummaryrefslogtreecommitdiff
path: root/tools/env
diff options
context:
space:
mode:
authorxypron.glpk@gmx.de2017-04-15 13:05:40 +0200
committerTom Rini2017-04-18 10:29:22 -0400
commitddc6a9de057e0fd0b46ba21d16a50a8d24351ef6 (patch)
tree4c21bd25dc7cedd6173aebc10e4fcb6614aa8e96 /tools/env
parent1ecd2a2f0600e61f2edff4fc3dce76f0f6559b67 (diff)
tools/env: avoid memory leak in fw_setenv
If realloc fails we should release the old buffer. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/env')
-rw-r--r--tools/env/fw_env.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 299e0c9608b..28616561830 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -473,6 +473,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;
int ret;
@@ -507,11 +508,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;
}