From 81fe037601c1afa5434d96fc45245aa4651d1fe9 Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 20 Jan 2013 21:28:05 +0000 Subject: sh: Move some stackmarks to fix high memory usage in some loops. If a loop contained certain commands (such as redirected compound commands), the temporary memory for the redirection was not freed between iterations of the loop but only after the loop. Put a stackmark in evaltree(), freeing memory whenever a node has been evaluated. Some other stackmarks are then redundant; remove them. Example: while :; do { :; } nfor.args ; argp ; argp = argp->narg.next) { oexitstatus = exitstatus; @@ -375,7 +377,6 @@ evalfor(union node *n, int flags) } } loopnest--; - popstackmark(&smark); exitstatus = status; } @@ -392,16 +393,13 @@ evalcase(union node *n) union node *cp; union node *patp; struct arglist arglist; - struct stackmark smark; - setstackmark(&smark); arglist.lastp = &arglist.list; oexitstatus = exitstatus; expandarg(n->ncase.expr, &arglist, EXP_TILDE); for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) { for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) { if (casematch(patp, arglist.list->text)) { - popstackmark(&smark); while (cp->nclist.next && cp->type == NCLISTFALLTHRU && cp->nclist.body == NULL) @@ -415,7 +413,6 @@ evalcase(union node *n) } } } - popstackmark(&smark); exitstatus = 0; return (NULL); } @@ -610,7 +607,7 @@ evalbackcmd(union node *n, struct backcmd *result) { int pip[2]; struct job *jp; - struct stackmark smark; /* unnecessary */ + struct stackmark smark; struct jmploc jmploc; struct jmploc *savehandler; struct localvar *savelocalvars; @@ -751,7 +748,6 @@ safe_builtin(int idx, int argc, char **argv) static void evalcommand(union node *cmd, int flags, struct backcmd *backcmd) { - struct stackmark smark; union node *argp; struct arglist arglist; struct arglist varlist; @@ -778,7 +774,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) /* First expand the arguments. */ TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags)); - setstackmark(&smark); arglist.lastp = &arglist.list; varlist.lastp = &varlist.list; varflag = 1; @@ -1149,7 +1144,6 @@ out: setvar("_", lastarg, 0); if (do_clearcmdentry) clearcmdentry(); - popstackmark(&smark); } -- cgit v1.1