summaryrefslogtreecommitdiffstats
path: root/usr.bin/env
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2005-07-18 22:18:16 +0000
committergad <gad@FreeBSD.org>2005-07-18 22:18:16 +0000
commitc60077abb1631b53cce873ab9bba69fe2316333b (patch)
treeb0044e44de1b5ea407496b16b5f68f0aea3c21fe /usr.bin/env
parent2f07911d656bcb8c1494eb55e5361778a9fb3d72 (diff)
downloadFreeBSD-src-c60077abb1631b53cce873ab9bba69fe2316333b.zip
FreeBSD-src-c60077abb1631b53cce873ab9bba69fe2316333b.tar.gz
Fix minor memory leak when expanding ${variable}s
Noticed by: Dave Hart MFC plans: after checking with re@
Diffstat (limited to 'usr.bin/env')
-rw-r--r--usr.bin/env/envopts.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/env/envopts.c b/usr.bin/env/envopts.c
index c62da6d..f821430 100644
--- a/usr.bin/env/envopts.c
+++ b/usr.bin/env/envopts.c
@@ -423,6 +423,7 @@ expand_vars(int in_thisarg, char **thisarg_p, char **dest_p, const char **src_p)
fprintf(stderr,
"#env replacing ${%s} with null string\n",
vname);
+ free(vname);
return (NULL);
}
@@ -435,8 +436,10 @@ expand_vars(int in_thisarg, char **thisarg_p, char **dest_p, const char **src_p)
* shorter than the ${VARNAME} reference that it replaces, then our
* caller can just copy the value to the existing destination.
*/
- if (strlen(vname) + 3 >= strlen(vvalue))
+ if (strlen(vname) + 3 >= strlen(vvalue)) {
+ free(vname);
return (vvalue);
+ }
/*
* The value is longer than the string it replaces, which means the
@@ -460,5 +463,6 @@ expand_vars(int in_thisarg, char **thisarg_p, char **dest_p, const char **src_p)
*newstr = '\0';
}
*dest_p = strchr(newstr, '\0');
+ free(vname);
return (vvalue);
}
OpenPOWER on IntegriCloud