memory leak in awk applet

Denis Vlasenko vda.linux at googlemail.com
Sat Feb 24 17:03:37 UTC 2007


On Friday 23 February 2007 23:31, Dick Streefland wrote:
> I noticed that awk leaks memory when you read the $<N> variables
> repeatably. You can easily reproduce this with the following script:
> 
> BEGIN{
> 	for (;;)
> 	{
> 		"echo foo" | getline;
> 		foo = $1;
> 	}
> }
> 
> The problem is that the same string is allocated by bb_xstrdup() over
> and over again. The following patch stops the leak, but I'm not
> completely sure if it is the right fix:
> 
> diff -pu busybox-1.4.1/editors/awk.c.orig busybox-1.4.1/editors/awk.c
> --- busybox-1.4.1/editors/awk.c.orig	2007-01-24 22:34:50.000000000 +0100
> +++ busybox-1.4.1/editors/awk.c	2007-02-23 23:28:36.000000000 +0100
> @@ -740,7 +740,7 @@ static var *copyvar(var *dest, const var
>  {
>  	if (dest != src) {
>  		clrvar(dest);
> -		dest->type |= (src->type & ~VF_DONTTOUCH);
> +		dest->type |= (src->type & ~(VF_DONTTOUCH|VF_FSTR));
>  		dest->number = src->number;
>  		if (src->string)
>  			dest->string = xstrdup(src->string);

Looks ok to me. Applied, thanks!
--
vda



More information about the busybox mailing list