diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-06 22:17:29 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-06 22:17:29 +0000 |
commit | 702ec5926f86653b5a20b7d856de6b3a4c11516f (patch) | |
tree | bb59e4863e4a72995f19364b9709c36e827d4a30 | |
parent | 8bb7df49c24de71f28b47eb2e3b86fb5b2e9d42a (diff) | |
download | busybox-702ec5926f86653b5a20b7d856de6b3a4c11516f.tar.gz |
Fix the memory leak. No really this time.
-Erik
-rw-r--r-- | lash.c | 16 | ||||
-rw-r--r-- | sh.c | 16 | ||||
-rw-r--r-- | shell/lash.c | 16 |
3 files changed, 27 insertions, 21 deletions
@@ -207,7 +207,7 @@ static char *local_pending_command = NULL; static struct jobset job_list = { NULL, NULL }; static int argc; static char **argv; -static struct close_me *close_me_head = NULL; +static struct close_me *close_me_head; #ifdef BB_FEATURE_SH_ENVIRONMENT static int last_bg_pid=-1; static int last_return_code=-1; @@ -631,9 +631,12 @@ static void mark_closed(int fd) static void close_all() { - struct close_me *c; - for (c=close_me_head; c; c=c->next) { - mark_closed(c->fd); + int i=0; + struct close_me *c, *tmp; + for (c=close_me_head; c; c=tmp) { + close(c->fd); + tmp=c->next; + free(c); } close_me_head = NULL; } @@ -1713,11 +1716,11 @@ int shell_main(int argc_l, char **argv_l) argc = argc_l; argv = argv_l; + /* These variables need re-initializing when recursing */ shell_context = 0; cwd=NULL; -#ifdef BB_FEATURE_SH_STANDALONE_SHELL - /* These variables need re-initializing when recursing */ local_pending_command = NULL; + close_me_head = NULL; job_list.head = NULL; job_list.fg = NULL; #ifdef BB_FEATURE_SH_ENVIRONMENT @@ -1725,7 +1728,6 @@ int shell_main(int argc_l, char **argv_l) last_return_code=-1; show_x_trace=FALSE; #endif -#endif if (argv[0] && argv[0][0] == '-') { FILE *prof_input; @@ -207,7 +207,7 @@ static char *local_pending_command = NULL; static struct jobset job_list = { NULL, NULL }; static int argc; static char **argv; -static struct close_me *close_me_head = NULL; +static struct close_me *close_me_head; #ifdef BB_FEATURE_SH_ENVIRONMENT static int last_bg_pid=-1; static int last_return_code=-1; @@ -631,9 +631,12 @@ static void mark_closed(int fd) static void close_all() { - struct close_me *c; - for (c=close_me_head; c; c=c->next) { - mark_closed(c->fd); + int i=0; + struct close_me *c, *tmp; + for (c=close_me_head; c; c=tmp) { + close(c->fd); + tmp=c->next; + free(c); } close_me_head = NULL; } @@ -1713,11 +1716,11 @@ int shell_main(int argc_l, char **argv_l) argc = argc_l; argv = argv_l; + /* These variables need re-initializing when recursing */ shell_context = 0; cwd=NULL; -#ifdef BB_FEATURE_SH_STANDALONE_SHELL - /* These variables need re-initializing when recursing */ local_pending_command = NULL; + close_me_head = NULL; job_list.head = NULL; job_list.fg = NULL; #ifdef BB_FEATURE_SH_ENVIRONMENT @@ -1725,7 +1728,6 @@ int shell_main(int argc_l, char **argv_l) last_return_code=-1; show_x_trace=FALSE; #endif -#endif if (argv[0] && argv[0][0] == '-') { FILE *prof_input; diff --git a/shell/lash.c b/shell/lash.c index b7c5ec525..72d8bb38b 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -207,7 +207,7 @@ static char *local_pending_command = NULL; static struct jobset job_list = { NULL, NULL }; static int argc; static char **argv; -static struct close_me *close_me_head = NULL; +static struct close_me *close_me_head; #ifdef BB_FEATURE_SH_ENVIRONMENT static int last_bg_pid=-1; static int last_return_code=-1; @@ -631,9 +631,12 @@ static void mark_closed(int fd) static void close_all() { - struct close_me *c; - for (c=close_me_head; c; c=c->next) { - mark_closed(c->fd); + int i=0; + struct close_me *c, *tmp; + for (c=close_me_head; c; c=tmp) { + close(c->fd); + tmp=c->next; + free(c); } close_me_head = NULL; } @@ -1713,11 +1716,11 @@ int shell_main(int argc_l, char **argv_l) argc = argc_l; argv = argv_l; + /* These variables need re-initializing when recursing */ shell_context = 0; cwd=NULL; -#ifdef BB_FEATURE_SH_STANDALONE_SHELL - /* These variables need re-initializing when recursing */ local_pending_command = NULL; + close_me_head = NULL; job_list.head = NULL; job_list.fg = NULL; #ifdef BB_FEATURE_SH_ENVIRONMENT @@ -1725,7 +1728,6 @@ int shell_main(int argc_l, char **argv_l) last_return_code=-1; show_x_trace=FALSE; #endif -#endif if (argv[0] && argv[0][0] == '-') { FILE *prof_input; |