aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2019-01-19 22:16:59 +0200
committerArnold D. Robbins <arnold@skeeve.com>2019-01-19 22:16:59 +0200
commit0efefad3d8ff61355002b828c13a531e15f55978 (patch)
tree29766aaa7e0f6e4b44ea816f28b2e8de08437f66 /main.c
parentb51d10b1697c8a95c25ec7b5d9781c4cd780dca4 (diff)
downloadegawk-0efefad3d8ff61355002b828c13a531e15f55978.tar.gz
egawk-0efefad3d8ff61355002b828c13a531e15f55978.tar.bz2
egawk-0efefad3d8ff61355002b828c13a531e15f55978.zip
Continue fixing memory leaks related to namespaces.
Diffstat (limited to 'main.c')
-rw-r--r--main.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/main.c b/main.c
index 3324b698..1eb6d6a9 100644
--- a/main.c
+++ b/main.c
@@ -471,10 +471,7 @@ main(int argc, char **argv)
if (do_intl)
exit(EXIT_SUCCESS);
- if (current_namespace != awk_namespace) {
- efree((char *) current_namespace);
- current_namespace = awk_namespace;
- }
+ set_current_namespace(awk_namespace);
install_builtins();
@@ -520,9 +517,7 @@ main(int argc, char **argv)
interpret(code_block);
if (do_pretty_print) {
- if (current_namespace != awk_namespace)
- efree((char *) current_namespace);
- current_namespace = awk_namespace;
+ set_current_namespace(awk_namespace);
dump_prog(code_block);
dump_funcs();
}
@@ -1806,3 +1801,14 @@ platform_name()
return "posix";
#endif
}
+
+/* set_current_namespace --- set current_namespace and handle memory management */
+
+void
+set_current_namespace(const char *new_namespace)
+{
+ if (current_namespace != awk_namespace)
+ efree((void *) current_namespace);
+
+ current_namespace = new_namespace;
+}