make DEBUG_LEAKS safely free all resources before the main shell exits

This commit is contained in:
tg 2013-02-10 18:17:30 +00:00
parent ce1ab97541
commit 43a41932e7
2 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.613 2013/01/12 02:25:01 tg Exp $' srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.614 2013/02/10 18:17:28 tg Exp $'
#- #-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 # 2011, 2012
@ -1529,7 +1529,7 @@ else
#define EXTERN #define EXTERN
#define MKSH_INCLUDES_ONLY #define MKSH_INCLUDES_ONLY
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.613 2013/01/12 02:25:01 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.614 2013/02/10 18:17:28 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); } int main(void) { printf("Hello, World!\n"); return (0); }
EOF EOF
case $cm in case $cm in
@ -2380,6 +2380,8 @@ HAVE_STRING_H ac_header
HAVE_CAN_FSTACKPROTECTORALL ac_flags HAVE_CAN_FSTACKPROTECTORALL ac_flags
==== cpp definitions ==== ==== cpp definitions ====
DEBUG enable debugging (want gcc), implies:
DEBUG_LEAKS enable freeing resources before exiting
MKSHRC_PATH "~/.mkshrc" (do not change) MKSHRC_PATH "~/.mkshrc" (do not change)
MKSH_A4PB force use of arc4random_pushb MKSH_A4PB force use of arc4random_pushb
MKSH_ASSUME_UTF8 (0=disabled, 1=enabled; default: unset) MKSH_ASSUME_UTF8 (0=disabled, 1=enabled; default: unset)

11
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.256 2013/02/10 17:55:57 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.257 2013/02/10 18:17:30 tg Exp $");
extern char **environ; extern char **environ;
@ -971,6 +971,8 @@ 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
@ -997,6 +999,13 @@ 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