broken commit: "memory leak in variable.c: fcn vareval(), free variable v created by cp_enqvar and used locally"

freeing stuff which is still used,
actually cp_enqvar is broken and needs fixing,
  but thats used at placed where ownership and usage is not clear
This commit is contained in:
rlar 2016-04-02 22:28:09 +02:00
parent 13b6a5fd40
commit 85fdadc683
2 changed files with 8 additions and 4 deletions

View File

@ -34,6 +34,9 @@ bool ft_ngdebug = FALSE, ft_stricterror = FALSE;
* plot and circuit environment variables.
*/
/* this is broken, returns sometimes "new" struct variable
* and sometimes already/still "used" struct variable (owned by someone else)
*/
struct variable *
cp_enqvar(char *word)
{
@ -73,8 +76,9 @@ cp_enqvar(char *word)
if (plot_cur) {
for (vv = plot_cur->pl_env; vv; vv = vv->va_next)
if (eq(vv->va_name, word))
return (vv);
return (vv); /* <= return an already used struct variable */
if (eq(word, "curplotname"))
/* return a new allocaed struct variable */
return var_alloc_string(copy(word), copy(plot_cur->pl_name), NULL);
if (eq(word, "curplottitle"))
return var_alloc_string(copy(word), copy(plot_cur->pl_title), NULL);

View File

@ -758,7 +758,7 @@ vareval(char *string)
vfree = v = cp_enqvar(string);
wl = wl_cons(copy(v ? "1" : "0"), NULL);
tfree(oldstring);
free_struct_variable(vfree);
free_struct_variable(vfree); /* bug: free still used struct variable */
return (wl);
case '#':
@ -780,7 +780,7 @@ vareval(char *string)
i = (v->va_type != CP_BOOL);
wl = wl_cons(tprintf("%d", i), NULL);
tfree(oldstring);
free_struct_variable(vfree);
free_struct_variable(vfree); /* bug: free still used struct variable */
return (wl);
case '\0':
@ -818,7 +818,7 @@ vareval(char *string)
return (NULL);
}
wl = cp_varwl(v);
free_struct_variable(vfree);
free_struct_variable(vfree); /* bug: free still used struct variable */
/* Now parse and deal with 'range' ... */
if (range) {