improve DEBUG_LEAKS handling and fix freeing some locs

This commit is contained in:
tg
2013-02-10 19:05:37 +00:00
parent af39f3b7b0
commit 2b06709bf3
2 changed files with 13 additions and 15 deletions

3
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #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 * in later versions we might use libtermcap for this, but since external
@ -5451,6 +5451,7 @@ x_init(void)
void void
x_done(void) x_done(void)
{ {
if (x_tab != NULL)
afreeall(AEDIT); afreeall(AEDIT);
} }
#endif #endif

21
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #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; extern char **environ;
@ -955,7 +955,7 @@ quitenv(struct shf *shf)
int fd; int fd;
yyrecursive_pop(true); yyrecursive_pop(true);
if (ep->oenv && ep->oenv->loc != ep->loc) while (ep->oenv && ep->oenv->loc != ep->loc)
popblock(); popblock();
if (ep->savefd != NULL) { if (ep->savefd != NULL) {
for (fd = 0; fd < NUFILE; fd++) 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. * Either main shell is exiting or cleanup_parents_env() was called.
*/ */
if (ep->oenv == NULL) { if (ep->oenv == NULL) {
struct block *l;
if (ep->type == E_NONE) { if (ep->type == E_NONE) {
/* Main shell exiting? */ /* Main shell exiting? */
#if HAVE_PERSISTENT_HISTORY #if HAVE_PERSISTENT_HISTORY
@ -999,17 +997,9 @@ quitenv(struct shf *shf)
} }
if (shf) if (shf)
shf_close(shf); shf_close(shf);
#ifdef DEBUG_LEAKS
l = e->loc;
while (l) {
afreeall(&l->area);
l = l->next;
}
#endif
reclaim(); reclaim();
#ifdef DEBUG_LEAKS #ifdef DEBUG_LEAKS
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
if (Flag(FTALKING))
x_done(); x_done();
#endif #endif
afreeall(APERM); afreeall(APERM);
@ -1074,6 +1064,13 @@ cleanup_proc_env(void)
static void static void
reclaim(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); remove_temps(e->temps);
e->temps = NULL; e->temps = NULL;
afreeall(&e->area); afreeall(&e->area);