Fixed memory leak on old style command substitution

such as  sh -c 'echo `echo foo`' .
The memory allocated with ckmalloc() at
parser.c:1349:readtoken1() (search for "done:" label)
was never freed.

I changed this to use 'string stack' framework of Ash.
Note that a string on string stack is properly freed on
exception and end of command parsing, and no explicit free
or signal handlings required.
See TOUR for an overview, and memalloc.[ch] for details
of string stack.
This commit is contained in:
itohy 1998-09-26 20:56:33 +00:00
parent 0a1a6fb7e0
commit ef88b5d2bd

View File

@ -1,4 +1,4 @@
/* $NetBSD: parser.c,v 1.39 1998/07/28 11:41:57 mycroft Exp $ */
/* $NetBSD: parser.c,v 1.40 1998/09/26 20:56:33 itohy Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
__RCSID("$NetBSD: parser.c,v 1.39 1998/07/28 11:41:57 mycroft Exp $");
__RCSID("$NetBSD: parser.c,v 1.40 1998/09/26 20:56:33 itohy Exp $");
#endif
#endif /* not lint */
@ -1346,8 +1346,7 @@ done:
STPUTC('\0', out);
savelen = out - stackblock();
if (savelen > 0) {
str = ckmalloc(savelen);
memcpy(str, stackblock(), savelen);
str = grabstackstr(out);
setinputstring(str, 1);
}
}