diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | txr.c | 27 | ||||
-rw-r--r-- | txr.h | 1 |
3 files changed, 15 insertions, 14 deletions
@@ -440,6 +440,7 @@ tst/tests/016/%: TXR_DBG_OPTS := tst/tests/017/%: TXR_DBG_OPTS := tst/tests/018/%: TXR_DBG_OPTS := tst/tests/019/%: TXR_DBG_OPTS := +tst/tests/019/load-hook.ok: TXR_DBG_OPTS := --free-all tst/tests/014/dgram-stream.ok: | tst/tests/014/socket-basic.ok @@ -80,6 +80,7 @@ int opt_noninteractive = if_full_repl(0, 1); int opt_noprofile; int opt_compat; int opt_dbg_expansion; +int opt_free_all; val stdlib_path; #if HAVE_FORK_STUFF @@ -415,6 +416,16 @@ static int license(void) return retval; } +static void free_all(void) +{ + if (opt_free_all) { + regex_free_all(); + gc_free_all(); + arith_free_all(); + free(progname); + } +} + int txr_main(int argc, char **argv); int main(int argc, char **argv) @@ -423,6 +434,7 @@ int main(int argc, char **argv) repress_privilege(); progname = utf8_dup_from(argv[0] ? argv[0]: "txr"); progname_u8 = argv[0]; + atexit(free_all); init(&stack_bottom); match_init(); debug_init(); @@ -518,19 +530,6 @@ static int gc_delta(val optval) return 1; } -static void free_all(void) -{ - static int called; - - if (!called) { - called = 1; - regex_free_all(); - gc_free_all(); - arith_free_all(); - free(progname); - } -} - #ifndef CONFIG_DEBUG_SUPPORT static void no_dbg_support(val arg) { @@ -932,7 +931,7 @@ int txr_main(int argc, char **argv) } else if (equal(opt, lit("free-all"))) { if (org) goto noarg; - atexit(free_all); + opt_free_all = 1; continue; } else if (equal(opt, lit("noprofile"))) { if (org) @@ -41,6 +41,7 @@ extern int opt_debugger; extern int opt_dbg_autoload; extern int opt_dbg_expansion; extern int opt_noprofile; +extern int opt_free_all; extern alloc_bytes_t opt_gc_delta; extern const wchli_t *version; extern wchar_t *progname; |