Fix minor memory leak when expanding ${variable}s

Noticed by:	Dave Hart
MFC plans:	after checking with re@
This commit is contained in:
Garance A Drosehn 2005-07-18 22:18:16 +00:00
parent 991e00dffb
commit 9afe6a5bf9

View File

@ -423,6 +423,7 @@ expand_vars(int in_thisarg, char **thisarg_p, char **dest_p, const char **src_p)
fprintf(stderr, fprintf(stderr,
"#env replacing ${%s} with null string\n", "#env replacing ${%s} with null string\n",
vname); vname);
free(vname);
return (NULL); 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 * shorter than the ${VARNAME} reference that it replaces, then our
* caller can just copy the value to the existing destination. * 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); return (vvalue);
}
/* /*
* The value is longer than the string it replaces, which means the * 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'; *newstr = '\0';
} }
*dest_p = strchr(newstr, '\0'); *dest_p = strchr(newstr, '\0');
free(vname);
return (vvalue); return (vvalue);
} }