memory leak in awk applet

Dick Streefland dick at streefland.net
Fri Feb 23 22:31:33 UTC 2007


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);

-- 
Dick



More information about the busybox mailing list