hush: plug the leak of expanded heredoc
This commit is contained in:
parent
efea9d2819
commit
1943aec2ec
15
shell/hush.c
15
shell/hush.c
@ -64,7 +64,6 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
|
||||||
//TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN?
|
//TODO: pull in some .h and find out whether we have SINGLE_APPLET_MAIN?
|
||||||
//#include "applet_tables.h" doesn't work
|
//#include "applet_tables.h" doesn't work
|
||||||
@ -79,6 +78,12 @@
|
|||||||
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
# define PIPE_BUF 4096 /* amount of buffering in a pipe */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Debug build knobs */
|
||||||
|
//#define LEAK_HUNTING 1
|
||||||
|
//#define WANT_TO_TEST_NOMMU 1
|
||||||
|
|
||||||
|
|
||||||
#ifdef WANT_TO_TEST_NOMMU
|
#ifdef WANT_TO_TEST_NOMMU
|
||||||
# undef BB_MMU
|
# undef BB_MMU
|
||||||
# undef USE_FOR_NOMMU
|
# undef USE_FOR_NOMMU
|
||||||
@ -214,8 +219,7 @@ static void debug_print_strings(const char *prefix, char **vv)
|
|||||||
/*
|
/*
|
||||||
* Leak hunting. Use hush_leaktool.sh for post-processing.
|
* Leak hunting. Use hush_leaktool.sh for post-processing.
|
||||||
*/
|
*/
|
||||||
//#define FOR_HUSH_LEAKTOOL
|
#ifdef LEAK_HUNTING
|
||||||
#ifdef FOR_HUSH_LEAKTOOL
|
|
||||||
static void *xxmalloc(int lineno, size_t size)
|
static void *xxmalloc(int lineno, size_t size)
|
||||||
{
|
{
|
||||||
void *ptr = xmalloc((size + 0xff) & ~0xff);
|
void *ptr = xmalloc((size + 0xff) & ~0xff);
|
||||||
@ -743,7 +747,7 @@ static char **add_strings_to_strings(char **strings, char **add, int need_to_dup
|
|||||||
v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]);
|
v[count1 + i] = (need_to_dup ? xstrdup(add[i]) : add[i]);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
#ifdef FOR_HUSH_LEAKTOOL
|
#ifdef LEAK_HUNTING
|
||||||
static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup)
|
static char **xx_add_strings_to_strings(int lineno, char **strings, char **add, int need_to_dup)
|
||||||
{
|
{
|
||||||
char **ptr = add_strings_to_strings(strings, add, need_to_dup);
|
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)
|
|||||||
v[1] = NULL;
|
v[1] = NULL;
|
||||||
return add_strings_to_strings(strings, v, /*dup:*/ 0);
|
return add_strings_to_strings(strings, v, /*dup:*/ 0);
|
||||||
}
|
}
|
||||||
#ifdef FOR_HUSH_LEAKTOOL
|
#ifdef LEAK_HUNTING
|
||||||
static char **xx_add_string_to_strings(int lineno, char **strings, char *add)
|
static char **xx_add_string_to_strings(int lineno, char **strings, char *add)
|
||||||
{
|
{
|
||||||
char **ptr = add_string_to_strings(strings, add);
|
char **ptr = add_string_to_strings(strings, add);
|
||||||
@ -2310,6 +2314,7 @@ static void setup_heredoc(struct redir_struct *redir)
|
|||||||
len -= written;
|
len -= written;
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
close(pair.wr);
|
close(pair.wr);
|
||||||
|
free(expanded);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
heredoc += written;
|
heredoc += written;
|
||||||
|
3
shell/hush_test/hush-z_slow/leak_heredoc1.right
Normal file
3
shell/hush_test/hush-z_slow/leak_heredoc1.right
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Warm up
|
||||||
|
Measuring memory leak...
|
||||||
|
Ok
|
34
shell/hush_test/hush-z_slow/leak_heredoc1.tests
Executable file
34
shell/hush_test/hush-z_slow/leak_heredoc1.tests
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
echo "Warm up"
|
||||||
|
i=1
|
||||||
|
while test $i != 99; do
|
||||||
|
: <<HERE
|
||||||
|
Hello $i `echo builtin_$i`
|
||||||
|
HERE
|
||||||
|
: $((i++))
|
||||||
|
done
|
||||||
|
|
||||||
|
memleak
|
||||||
|
|
||||||
|
echo "Measuring memory leak..."
|
||||||
|
i=1
|
||||||
|
while test $i != 99; do
|
||||||
|
: <<HERE
|
||||||
|
Hello $i `echo builtin_$i`
|
||||||
|
HERE
|
||||||
|
: $((i++))
|
||||||
|
done
|
||||||
|
i=1
|
||||||
|
while test $i != 99; do
|
||||||
|
: <<HERE
|
||||||
|
Hello $i `echo builtin_$i`
|
||||||
|
HERE
|
||||||
|
: $((i++))
|
||||||
|
done
|
||||||
|
|
||||||
|
memleak
|
||||||
|
kb=$?
|
||||||
|
if test $kb -le 4; then
|
||||||
|
echo Ok #$kb
|
||||||
|
else
|
||||||
|
echo "Bad: $kb kb (or more) leaked"
|
||||||
|
fi
|
@ -14,7 +14,6 @@
|
|||||||
*
|
*
|
||||||
* Original BSD copyright notice is retained at the end of this file.
|
* Original BSD copyright notice is retained at the end of this file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
@ -22,7 +21,7 @@
|
|||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#else
|
#else
|
||||||
# include "busybox.h"
|
# include "libbb.h"
|
||||||
#endif
|
#endif
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
* rewrote arith (see notes to this), added locale support,
|
* rewrote arith (see notes to this), added locale support,
|
||||||
* rewrote dynamic variables.
|
* rewrote dynamic variables.
|
||||||
*/
|
*/
|
||||||
|
#include "libbb.h"
|
||||||
#include "busybox.h"
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
#define a_e_h_t arith_eval_hooks_t
|
#define a_e_h_t arith_eval_hooks_t
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
*
|
*
|
||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user