ash: eval: avoid leaking memory associated with redirections. Closes 7748
authorRon Yorston <rmy@pobox.com>
Mon, 25 Feb 2019 08:29:38 +0000 (08:29 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 25 Feb 2019 17:57:59 +0000 (18:57 +0100)
commitf55161ad27b641f6e09c6c498fa8a2bdb1112b0a
tree8ea2b3a9922ffd0b3fc8b47b7a997130e80bb7ce
parente563f9e851c78f5c13cb9828ddb11ca981fd6331
ash: eval: avoid leaking memory associated with redirections. Closes 7748

The following constructs result in ever-increasing memory usage:

   while true; do { true; } </dev/null; done
   while true; do ( true; ) </dev/null; done

For comparison, bash displays static memory usage in both cases.

This has been fixed in dash by commit 2bc6caa.  The maintainer
writes:

   I have simplified evaltree so that it simply sets the stack mark
   unconditionally.  This allows us to remove the stack marks in the
   functions called by evaltree.

Closes BusyBox bug 7748.

function                                             old     new   delta
evaltree                                             606     632     +26
evalcommand                                         1724    1696     -28
evalcase                                             382     351     -31
evalfor                                              230     196     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 26/-93)            Total: -67 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c