sh: Make sure to popredir() even if a function caused an error.

This commit is contained in:
Jilles Tjoelker 2010-03-06 17:31:09 +00:00
parent 544754df6f
commit 1749097497
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=204802
2 changed files with 17 additions and 1 deletions

View File

@ -813,7 +813,6 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
#ifdef DEBUG
trputs("Shell function: "); trargs(argv);
#endif
redirect(cmd->ncmd.redirect, REDIR_PUSH);
saveparam = shellparam;
shellparam.malloc = 0;
shellparam.reset = 1;
@ -831,6 +830,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
else {
freeparam(&shellparam);
shellparam = saveparam;
if (exception == EXERROR || exception == EXEXEC)
popredir();
}
unreffunc(cmdentry.u.func);
poplocalvars();
@ -841,6 +842,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
}
handler = &jmploc;
funcnest++;
redirect(cmd->ncmd.redirect, REDIR_PUSH);
INTON;
for (sp = varlist.list ; sp ; sp = sp->next)
mklocal(sp->text);

View File

@ -0,0 +1,14 @@
# $FreeBSD$
failures=0
check() {
if ! eval "[ $* ]"; then
echo "Failed: $*"
: $((failures += 1))
fi
}
check '"$(f() { shift x; }; { command eval f 2>/dev/null; } >/dev/null; echo hi)" = hi'
exit $((failures > 0))