From: xypron.glpk@gmx.de Date: Sat, 15 Apr 2017 11:05:40 +0000 (+0200) Subject: tools/env: avoid memory leak in fw_setenv X-Git-Tag: v2025.01-rc5-pxa1908~7157 X-Git-Url: http://git.dujemihanovic.xyz/html/%7B%7B%20.RelPermalink%20%7D%7D?a=commitdiff_plain;h=ddc6a9de057e0fd0b46ba21d16a50a8d24351ef6;p=u-boot.git tools/env: avoid memory leak in fw_setenv If realloc fails we should release the old buffer. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 299e0c9608..2861656183 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; }