Fix memory leak when parsing backticks (``).

This commit is contained in:
Jilles Tjoelker 2009-12-30 17:16:49 +00:00
parent 73c4bad04d
commit fe0533fd12
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=201262

View File

@ -1311,11 +1311,16 @@ parsebackq: {
int savelen;
int saveprompt;
const int bq_startlinno = plinno;
char *volatile ostr = NULL;
struct parsefile *const savetopfile = getcurrentfile();
str = NULL;
if (setjmp(jmploc.loc)) {
popfilesupto(savetopfile);
if (str)
ckfree(str);
if (ostr)
ckfree(ostr);
handler = savehandler;
if (exception == EXERROR) {
startlinno = bq_startlinno;
@ -1335,13 +1340,12 @@ parsebackq: {
/* We must read until the closing backquote, giving special
treatment to some slashes, and then push the string and
reread it as input, interpreting it normally. */
char *out;
char *oout;
int c;
int savelen;
char *str;
int olen;
STARTSTACKSTR(out);
STARTSTACKSTR(oout);
for (;;) {
if (needprompt) {
setprompt(2);
@ -1368,7 +1372,7 @@ parsebackq: {
}
if (c != '\\' && c != '`' && c != '$'
&& (!dblquote || c != '"'))
STPUTC('\\', out);
STPUTC('\\', oout);
break;
case '\n':
@ -1384,16 +1388,16 @@ parsebackq: {
default:
break;
}
STPUTC(c, out);
STPUTC(c, oout);
}
done:
STPUTC('\0', out);
savelen = out - stackblock();
if (savelen > 0) {
str = ckmalloc(savelen);
memcpy(str, stackblock(), savelen);
setinputstring(str, 1);
}
STPUTC('\0', oout);
olen = oout - stackblock();
INTOFF;
ostr = ckmalloc(olen);
memcpy(ostr, stackblock(), olen);
setinputstring(ostr, 1);
INTON;
}
nlpp = &bqlist;
while (*nlpp)
@ -1435,6 +1439,12 @@ parsebackq: {
str = NULL;
INTON;
}
if (ostr) {
INTOFF;
ckfree(ostr);
ostr = NULL;
INTON;
}
handler = savehandler;
if (arinest || dblquote)
USTPUTC(CTLBACKQ | CTLQUOTE, out);