From b112dc08c6c86b8b82d60b1169ccab51921241ca Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Thu, 27 May 2010 15:03:46 +0800 Subject: [REDIR] Fix popredir on abnormal exit from built-in Just like the poplocalvar problem recently fixed, redirections can also be leaked in case of an abnormal exit. This patch fixes it using the same method as poplocalvar, by storing the previous redirection state and restoring to that point. Signed-off-by: Herbert Xu --- src/eval.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index 59bded9..d5c1e6c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -219,6 +219,7 @@ evaltree(union node *n, int flags) goto setstatus; case NREDIR: expredir(n->nredir.redirect); + pushredir(n->nredir.redirect); status = redirectsafe(n->nredir.redirect, REDIR_PUSH); if (!status) { evaltree(n->nredir.n, flags & EV_TESTED); @@ -683,6 +684,7 @@ evalcommand(union node *cmd, int flags) #endif { struct localvar_list *localvar_stop; + struct redirtab *redir_stop; struct stackmark smark; union node *argp; struct arglist arglist; @@ -740,6 +742,7 @@ evalcommand(union node *cmd, int flags) preverrout.fd = 2; expredir(cmd->ncmd.redirect); + redir_stop = pushredir(cmd->ncmd.redirect); status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH|REDIR_SAVEFD2); path = vpath.text; @@ -882,6 +885,7 @@ raise: out: if (cmd->ncmd.redirect) popredir(execcmd); + unwindredir(redir_stop); unwindlocalvars(localvar_stop); if (lastarg) /* dsl: I think this is intended to be used to support -- cgit 1.4.1