shithub: trueawk

Download patch

ref: 821c502359855d0c43be8e9b08f037ecb543d310
parent: 4da7f6957e1934deaea782b653e6242713d2a9b6
author: Miguel Pineiro Jr <mpj@pineiro.cc>
date: Tue Aug 30 11:27:27 EDT 2022

Stop leaking tempcells from extra arguments in format

===============> cat leak.sh
#/bin/sh

# Monitor awk's memory consumption while repeatedly calling printf
# with extra, tempcell-producing expression arguments.

${1:-./a.out} '
BEGIN {
	mem = "ps -p $PPID -o rsz="
	system(mem)
	while (++i <= 100000) {
		printf("%d", 1+2, 3+4, 5+6, 7+8, 9+0) > "/dev/null"
		if (i % 10000 == 0)
			system(mem)
	}
}
' 2>/dev/null
===============> paste <(./leak.sh ./master.out) <(./leak.sh ./a.out)
 2572	 2564
 4804	 2600
 6996	 2600
 9192	 2600
11384	 2600
13576	 2600
15772	 2600
17964	 2600
20160	 2600
22352	 2600
24548	 2600

--- a/run.c
+++ b/run.c
@@ -971,8 +971,10 @@
 	}
 	*p = '\0';
 	free(fmt);
-	for ( ; a; a = a->nnext)		/* evaluate any remaining args */
-		execute(a);
+	for ( ; a; a = a->nnext) {		/* evaluate any remaining args */
+		x = execute(a);
+		tempfree(x);
+	}
 	*pbuf = buf;
 	*pbufsize = bufsize;
 	return p - buf;
--