Duplicate the variable name in the v->name field, as otherwise it points to

data that will be modified.  And do the appropriate thing now and free the
v->name buffer along with other relinquished memory.

XXX There is duplication here of destroying a Var, which is probably bogus,
and probably missed in a few places.
This commit is contained in:
jmallett 2002-10-24 04:10:55 +00:00
parent fa069ae5db
commit e5558b972a

View File

@ -1631,7 +1631,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
* so kludge up a Var structure for the modifications
*/
v = (Var *) emalloc(sizeof(Var));
v->name = &str[1];
v->name = estrdup(str);
v->val = Buf_Init(1);
v->flags = VAR_JUNK;
}
@ -2201,6 +2201,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
*/
*freePtr = TRUE;
}
free(v->name);
Buf_Destroy(v->val, destroy);
free(v);
} else if (v->flags & VAR_JUNK) {
@ -2212,6 +2213,7 @@ Var_Parse(char *str, GNode *ctxt, Boolean err, int *lengthPtr, Boolean *freePtr)
free(str);
}
*freePtr = FALSE;
free(v->name);
Buf_Destroy(v->val, TRUE);
free(v);
if (dynamic) {