summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-01-20 21:28:05 +0000
committerjilles <jilles@FreeBSD.org>2013-01-20 21:28:05 +0000
commit81fe037601c1afa5434d96fc45245aa4651d1fe9 (patch)
tree6d0d47674786303c35822413e91e7f2da36f05d9 /bin/sh
parent51fe15e2975672156b28514cc440be72cd1c9bd7 (diff)
downloadFreeBSD-src-81fe037601c1afa5434d96fc45245aa4651d1fe9.zip
FreeBSD-src-81fe037601c1afa5434d96fc45245aa4651d1fe9.tar.gz
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 { :; } </dev/null; done
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/eval.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 98261e9..7817806 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -193,7 +193,9 @@ evaltree(union node *n, int flags)
{
int do_etest;
union node *next;
+ struct stackmark smark;
+ setstackmark(&smark);
do_etest = 0;
if (n == NULL) {
TRACE(("evaltree(NULL) called\n"));
@@ -292,8 +294,10 @@ evaltree(union node *n, int flags)
break;
}
n = next;
+ popstackmark(&smark);
} while (n != NULL);
out:
+ popstackmark(&smark);
if (pendingsigs)
dotrap();
if (eflag && exitstatus != 0 && do_etest)
@@ -347,10 +351,8 @@ evalfor(union node *n, int flags)
struct arglist arglist;
union node *argp;
struct strlist *sp;
- struct stackmark smark;
int status;
- setstackmark(&smark);
arglist.lastp = &arglist.list;
for (argp = n->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);
}
OpenPOWER on IntegriCloud