aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-09 14:15:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-09 14:15:57 +0000
commit1943aec2ec390d9fda159aa0412362780ec83f09 (patch)
treeec9ddd365d2232d9fb621b79000cbf20f1410cda
parentefea9d2819165b414b81a47c8227ae007bd5382a (diff)
downloadbusybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.tar.gz
busybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.tar.bz2
busybox-w32-1943aec2ec390d9fda159aa0412362780ec83f09.zip
hush: plug the leak of expanded heredoc
-rw-r--r--shell/hush.c15
-rw-r--r--shell/hush_test/hush-z_slow/leak_heredoc1.right3
-rwxr-xr-xshell/hush_test/hush-z_slow/leak_heredoc1.tests34
-rw-r--r--shell/match.c3
-rw-r--r--shell/math.c3
-rw-r--r--shell/msh.c1
6 files changed, 49 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c
index d791b62d0..4c2716ddd 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -64,7 +64,6 @@
64 * 64 *
65 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 65 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
66 */ 66 */
67
68#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ 67#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
69//TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN? 68//TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN?
70//#include "applet_tables.h" doesn't work 69//#include "applet_tables.h" doesn't work
@@ -79,6 +78,12 @@
79# define PIPE_BUF 4096 /* amount of buffering in a pipe */ 78# define PIPE_BUF 4096 /* amount of buffering in a pipe */
80#endif 79#endif
81 80
81
82/* Debug build knobs */
83//#define LEAK_HUNTING 1
84//#define WANT_TO_TEST_NOMMU 1
85
86
82#ifdef WANT_TO_TEST_NOMMU 87#ifdef WANT_TO_TEST_NOMMU
83# undef BB_MMU 88# undef BB_MMU
84# undef USE_FOR_NOMMU 89# undef USE_FOR_NOMMU
@@ -214,8 +219,7 @@ static void debug_print_strings(const char *prefix, char **vv)
214/* 219/*
215 * Leak hunting. Use hush_leaktool.sh for post-processing. 220 * Leak hunting. Use hush_leaktool.sh for post-processing.
216 */ 221 */
217//#define FOR_HUSH_LEAKTOOL 222#ifdef LEAK_HUNTING
218#ifdef FOR_HUSH_LEAKTOOL
219static void *xxmalloc(int lineno, size_t size) 223static void *xxmalloc(int lineno, size_t size)
220{ 224{
221 void *ptr = xmalloc((size + 0xff) & ~0xff); 225 void *ptr = xmalloc((size + 0xff) & ~0xff);
@@ -743,7 +747,7 @@ static char **add_strings_to_strings(char **strings, char **add, int need_to_dup
743 v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]); 747 v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]);
744 return v; 748 return v;
745} 749}
746#ifdef FOR_HUSH_LEAKTOOL 750#ifdef LEAK_HUNTING
747static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup) 751static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup)
748{ 752{
749 char **ptr = add_strings_to_strings(strings, add, need_to_dup); 753 char **ptr = add_strings_to_strings(strings, add, need_to_dup);
@@ -761,7 +765,7 @@ static char **add_string_to_strings(char **strings, char *add)
761 v[1] = NULL; 765 v[1] = NULL;
762 return add_strings_to_strings(strings, v, /*dup:*/ 0); 766 return add_strings_to_strings(strings, v, /*dup:*/ 0);
763} 767}
764#ifdef FOR_HUSH_LEAKTOOL 768#ifdef LEAK_HUNTING
765static char **xx_add_string_to_strings(int lineno, char **strings, char *add) 769static char **xx_add_string_to_strings(int lineno, char **strings, char *add)
766{ 770{
767 char **ptr = add_string_to_strings(strings, add); 771 char **ptr = add_string_to_strings(strings, add);
@@ -2310,6 +2314,7 @@ static void setup_heredoc(struct redir_struct *redir)
2310 len -= written; 2314 len -= written;
2311 if (len == 0) { 2315 if (len == 0) {
2312 close(pair.wr); 2316 close(pair.wr);
2317 free(expanded);
2313 return; 2318 return;
2314 } 2319 }
2315 heredoc += written; 2320 heredoc += written;
diff --git a/shell/hush_test/hush-z_slow/leak_heredoc1.right b/shell/hush_test/hush-z_slow/leak_heredoc1.right
new file mode 100644
index 000000000..c6f0334f3
--- /dev/null
+++ b/shell/hush_test/hush-z_slow/leak_heredoc1.right
@@ -0,0 +1,3 @@
1Warm up
2Measuring memory leak...
3Ok
diff --git a/shell/hush_test/hush-z_slow/leak_heredoc1.tests b/shell/hush_test/hush-z_slow/leak_heredoc1.tests
new file mode 100755
index 000000000..26cbb28a4
--- /dev/null
+++ b/shell/hush_test/hush-z_slow/leak_heredoc1.tests
@@ -0,0 +1,34 @@
1echo "Warm up"
2i=1
3while test $i != 99; do
4 : <<HERE
5Hello $i `echo builtin_$i`
6HERE
7 : $((i++))
8done
9
10memleak
11
12echo "Measuring memory leak..."
13i=1
14while test $i != 99; do
15 : <<HERE
16Hello $i `echo builtin_$i`
17HERE
18 : $((i++))
19done
20i=1
21while test $i != 99; do
22 : <<HERE
23Hello $i `echo builtin_$i`
24HERE
25 : $((i++))
26done
27
28memleak
29kb=$?
30if test $kb -le 4; then
31 echo Ok #$kb
32else
33 echo "Bad: $kb kb (or more) leaked"
34fi
diff --git a/shell/match.c b/shell/match.c
index 0810fd8f6..47038d667 100644
--- a/shell/match.c
+++ b/shell/match.c
@@ -14,7 +14,6 @@
14 * 14 *
15 * Original BSD copyright notice is retained at the end of this file. 15 * Original BSD copyright notice is retained at the end of this file.
16 */ 16 */
17
18#ifdef STANDALONE 17#ifdef STANDALONE
19# include <stdbool.h> 18# include <stdbool.h>
20# include <stdio.h> 19# include <stdio.h>
@@ -22,7 +21,7 @@
22# include <string.h> 21# include <string.h>
23# include <unistd.h> 22# include <unistd.h>
24#else 23#else
25# include "busybox.h" 24# include "libbb.h"
26#endif 25#endif
27#include <fnmatch.h> 26#include <fnmatch.h>
28#include "match.h" 27#include "match.h"
diff --git a/shell/math.c b/shell/math.c
index 8a44c8e88..cc298bd24 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -26,8 +26,7 @@
26 * rewrote arith (see notes to this), added locale support, 26 * rewrote arith (see notes to this), added locale support,
27 * rewrote dynamic variables. 27 * rewrote dynamic variables.
28 */ 28 */
29 29#include "libbb.h"
30#include "busybox.h"
31#include "math.h" 30#include "math.h"
32 31
33#define a_e_h_t arith_eval_hooks_t 32#define a_e_h_t arith_eval_hooks_t
diff --git a/shell/msh.c b/shell/msh.c
index da1dc3576..dffacf02a 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -12,7 +12,6 @@
12 * 12 *
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15
16#include <sys/times.h> 15#include <sys/times.h>
17#include <setjmp.h> 16#include <setjmp.h>
18 17