From 7deb42aafdf547a3648f60ff04e0114c10a3d18d Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 2 Aug 2009 16:05:42 +0000 Subject: - Fix Savannah bug #27093 - Fix Savannah bug #27143 - Fix Savannah bug #23960 - Fix Savannah bug #27148 --- variable.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 92a96ec..10bbc54 100644 --- a/variable.c +++ b/variable.c @@ -1091,7 +1091,7 @@ do_variable_definition (const struct floc *flocp, const char *varname, unsigned int oldlen, vallen; const char *val; - char *tp; + char *tp = NULL; val = value; if (v->recursive) @@ -1104,15 +1104,17 @@ do_variable_definition (const struct floc *flocp, const char *varname, when it was set; and from the expanded new value. Allocate memory for the expansion as we may still need the rest of the buffer if we're looking at a target-specific variable. */ - val = alloc_value = allocated_variable_expand (val); + val = tp = allocated_variable_expand (val); oldlen = strlen (v->value); vallen = strlen (val); - tp = alloca (oldlen + 1 + vallen + 1); - memcpy (tp, v->value, oldlen); - tp[oldlen] = ' '; - memcpy (&tp[oldlen + 1], val, vallen + 1); - p = tp; + p = alloc_value = xmalloc (oldlen + 1 + vallen + 1); + memcpy (alloc_value, v->value, oldlen); + alloc_value[oldlen] = ' '; + memcpy (&alloc_value[oldlen + 1], val, vallen + 1); + + if (tp) + free (tp); } } } @@ -1220,10 +1222,10 @@ do_variable_definition (const struct floc *flocp, const char *varname, } else { - if (alloc_value) - free (alloc_value); + char *tp = alloc_value; alloc_value = allocated_variable_expand (p); + if (find_and_set_default_shell (alloc_value)) { v = define_variable_in_set (varname, strlen (varname), p, @@ -1236,6 +1238,9 @@ do_variable_definition (const struct floc *flocp, const char *varname, } else v = lookup_variable (varname, strlen (varname)); + + if (tp) + free (tp); } } else -- cgit v1.2.3