From 2b06709bf3e9158cd5f64df6cd1d7a757f2b9c4b Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 10 Feb 2013 19:05:37 +0000 Subject: [PATCH] improve DEBUG_LEAKS handling and fix freeing some locs --- edit.c | 5 +++-- main.c | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/edit.c b/edit.c index c465680..12fb4eb 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.264 2013/02/10 17:41:03 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.265 2013/02/10 19:05:36 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -5451,7 +5451,8 @@ x_init(void) void x_done(void) { - afreeall(AEDIT); + if (x_tab != NULL) + afreeall(AEDIT); } #endif #endif /* !MKSH_NO_CMDLINE_EDITING */ diff --git a/main.c b/main.c index 4f99edd..b9c9d9c 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.257 2013/02/10 18:17:30 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.258 2013/02/10 19:05:37 tg Exp $"); extern char **environ; @@ -955,7 +955,7 @@ quitenv(struct shf *shf) int fd; yyrecursive_pop(true); - if (ep->oenv && ep->oenv->loc != ep->loc) + while (ep->oenv && ep->oenv->loc != ep->loc) popblock(); if (ep->savefd != NULL) { for (fd = 0; fd < NUFILE; fd++) @@ -971,8 +971,6 @@ quitenv(struct shf *shf) * Either main shell is exiting or cleanup_parents_env() was called. */ if (ep->oenv == NULL) { - struct block *l; - if (ep->type == E_NONE) { /* Main shell exiting? */ #if HAVE_PERSISTENT_HISTORY @@ -999,18 +997,10 @@ quitenv(struct shf *shf) } if (shf) shf_close(shf); -#ifdef DEBUG_LEAKS - l = e->loc; - while (l) { - afreeall(&l->area); - l = l->next; - } -#endif reclaim(); #ifdef DEBUG_LEAKS #ifndef MKSH_NO_CMDLINE_EDITING - if (Flag(FTALKING)) - x_done(); + x_done(); #endif afreeall(APERM); if (tty_fd >= 0) @@ -1074,6 +1064,13 @@ cleanup_proc_env(void) static void reclaim(void) { + struct block *l; + + while ((l = e->loc) && (!e->oenv || e->oenv->loc != l)) { + e->loc = l->next; + afreeall(&l->area); + } + remove_temps(e->temps); e->temps = NULL; afreeall(&e->area);