aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-05-09 11:42:52 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-05-09 11:42:52 +0300
commit12857707435f1d4bf9adf33b6fbfd57ff91529a7 (patch)
treef41897206773d57a9fc040785446144ab464cba4
parent123402fa15ec56d510ddd4cba16a5aea88e18023 (diff)
downloadegawk-12857707435f1d4bf9adf33b6fbfd57ff91529a7.tar.gz
egawk-12857707435f1d4bf9adf33b6fbfd57ff91529a7.tar.bz2
egawk-12857707435f1d4bf9adf33b6fbfd57ff91529a7.zip
Fix memory leak in do_eval.
-rw-r--r--ChangeLog2
-rw-r--r--awk.h1
-rw-r--r--awkgram.c9
-rw-r--r--awkgram.y9
-rw-r--r--debug.c5
5 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 68958a72..3bcb78e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@
<jchaloup@redhat.com>. Apparently introduced with move to
SYMTAB and FUNCTAB, but only showed up on Fedora 20 and Ubuntu 14.04,
which have a newer glibc.
+ (do_eval): Fix a memory leak seen by valgrind on Fedora 20 and
+ Ubuntu 14.04: the new SRCFILE that is added wasn't released.
2014-05-04 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/awk.h b/awk.h
index 5f420936..65448400 100644
--- a/awk.h
+++ b/awk.h
@@ -1372,6 +1372,7 @@ extern NODE *stopme(int nargs);
extern void shadow_funcs(void);
extern int check_special(const char *name);
extern SRCFILE *add_srcfile(enum srctype stype, char *src, SRCFILE *curr, bool *already_included, int *errcode);
+extern void free_srcfile(SRCFILE *thisfile);
extern void register_deferred_variable(const char *name, NODE *(*load_func)(void));
extern int files_are_same(char *path, SRCFILE *src);
extern void valinfo(NODE *n, Func_print print_func, FILE *fp);
diff --git a/awkgram.c b/awkgram.c
index 80d6ea05..7d444fb8 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4672,6 +4672,15 @@ parse_program(INSTRUCTION **pcode)
return (ret || errcount);
}
+/* free_srcfile --- free a SRCFILE struct */
+
+void
+free_srcfile(SRCFILE *thisfile)
+{
+ efree(thisfile->src);
+ efree(thisfile);
+}
+
/* do_add_srcfile --- add one item to srcfiles */
static SRCFILE *
diff --git a/awkgram.y b/awkgram.y
index 7d530b7f..07131d22 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2333,6 +2333,15 @@ parse_program(INSTRUCTION **pcode)
return (ret || errcount);
}
+/* free_srcfile --- free a SRCFILE struct */
+
+void
+free_srcfile(SRCFILE *thisfile)
+{
+ efree(thisfile->src);
+ efree(thisfile);
+}
+
/* do_add_srcfile --- add one item to srcfiles */
static SRCFILE *
diff --git a/debug.c b/debug.c
index 1ff43bd6..32b308af 100644
--- a/debug.c
+++ b/debug.c
@@ -5448,6 +5448,7 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
int ecount = 0, pcount = 0;
int ret;
int save_flags = do_flags;
+ SRCFILE *the_source;
if (prog_running) {
this_frame = find_frame(0);
@@ -5458,7 +5459,7 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
ctxt = new_context();
ctxt->install_func = append_symbol; /* keep track of newly installed globals */
push_context(ctxt);
- (void) add_srcfile(SRC_CMDLINE, arg->a_string, srcfiles, NULL, NULL);
+ the_source = add_srcfile(SRC_CMDLINE, arg->a_string, srcfiles, NULL, NULL);
do_flags = false;
ret = parse_program(&code);
do_flags = save_flags;
@@ -5575,6 +5576,8 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
* destroy_symbol(f); // destroy "@eval"
*/
+ free_srcfile(the_source);
+
return false;
}