Static-ify a variable. make du work with all the human-readable variants
[oweals/busybox.git] / sh.c
diff --git a/sh.c b/sh.c
index 57d969e40a235ce7a92410469779f44c3c47a704..150055bb142b00f62ac4e73c02453e350adb9571 100644 (file)
--- a/sh.c
+++ b/sh.c
@@ -153,6 +153,7 @@ static int run_command_predicate(char *cmd);
 /* function prototypes for shell stuff */
 static void mark_open(int fd);
 static void mark_closed(int fd);
+static void close_all(void);
 static void checkjobs(struct jobset *job_list);
 static int get_command(FILE * source, char *command);
 static int parse_command(char **command_ptr, struct job *job, int *inbg);
@@ -206,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;
@@ -630,9 +631,11 @@ static void mark_closed(int fd)
 
 static void close_all()
 {
-       struct close_me *c;
-       for (c=close_me_head; c; c=c->next) {
+       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;
 }
@@ -1712,18 +1715,17 @@ 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
        last_bg_pid=-1;
        last_return_code=-1;
        show_x_trace=FALSE;
-#endif
 #endif
 
        if (argv[0] && argv[0][0] == '-') {