From 0fb67b8d66ffd47ede0a0a5d09380943722414e9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 5 Mar 2018 10:50:21 -0500 Subject: [PATCH] leak fix for scripted returns --- Makefile | 2 +- builtins.c | 13 +++++++------ parser.c | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c588c8f..8bca3c1 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,4 @@ all: $(CC) $(CFLAGS) -c variable.c $(AR) r libinterp.a *.o @rm -f *.o - #$(CC) $(CFLAGS) shell.c *.o -o shell #-L. -l interp + #$(CC) $(CFLAGS) shell.c *.o -o shell diff --git a/builtins.c b/builtins.c index 309e1d8..b2295c5 100644 --- a/builtins.c +++ b/builtins.c @@ -94,15 +94,13 @@ int ifunc_do(interpreter *it) int ifunc_while(interpreter *it) { - //int c = igetarg_integer(it, 0); + int c = igetarg_integer(it, 0); ipop(it); int nidx = (int)ipop(it); - //if (c != 0) { + if (c != 0) { //ipush(it, (void *)nidx); it->lnidx = nidx - 1; - //} else { - // c++; - //} + } ipush(it, 0); return 0; } @@ -126,7 +124,10 @@ void iret(interpreter *it, variable *v) if (it->ret != 0) { it->ret->valtype = v->valtype; it->ret->value = v->value; - it->ret->svalue = v->svalue; + char *s = it->ret->svalue; + if (s != 0 && s != str_undef) + free(s); + it->ret->svalue = strclone(v->svalue); it->ret = 0; } } diff --git a/parser.c b/parser.c index 0c88cb0..5608998 100644 --- a/parser.c +++ b/parser.c @@ -39,9 +39,9 @@ void iend(interpreter *it) { for (unsigned int i = 0; i < MAX_VARS; i++) { if (it->vars[i].used == 1) { - char *s = it->vars[i].svalue; - if (s != 0 && s != str_undef && s != str_func) - free(s); + //char *s = it->vars[i].svalue; + //if (s != 0 && s != str_undef && s != str_func) + // free(s); free(it->vnames[i]); } }