projects
/
project
/
bcm63xx
/
u-boot.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1ecd2a2
)
tools/env: avoid memory leak in fw_setenv
author
[email protected]
<
[email protected]
>
Sat, 15 Apr 2017 11:05:40 +0000
(13:05 +0200)
committer
Tom Rini
<
[email protected]
>
Tue, 18 Apr 2017 14:29:22 +0000
(10:29 -0400)
If realloc fails we should release the old buffer.
Signed-off-by: Heinrich Schuchardt <
[email protected]
>
Reviewed-by: Tom Rini <
[email protected]
>
Reviewed-by: Simon Glass <
[email protected]
>
tools/env/fw_env.c
patch
|
blob
|
history
diff --git
a/tools/env/fw_env.c
b/tools/env/fw_env.c
index 299e0c9608bb2bc3b9e0298929726c14a337f96c..286165618304f9259daadde0c8262f10265539ca 100644
(file)
--- 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;
}