ref: 4da7f6957e1934deaea782b653e6242713d2a9b6
parent: 13cb1f4bb3a03bf42eba8cbe52f2b83c11774807
author: Miguel Pineiro Jr <mpj@pineiro.cc>
date: Tue Aug 30 10:43:34 EDT 2022
Stop leaking tempcells from extra args in bltin
===============> cat leak.sh
#/bin/sh
# Monitor awk's memory consumption while repeatedly calling int()
# with extra, tempcell-producing expression arguments. There is
# nothing special about int(). Most of the other functions in
# run.c/bltin() will do.
${1:-./a.out} '
BEGIN {
mem = "ps -p $PPID -o rsz="
system(mem)
while (++i <= 100000) {
int(1+2, 3+4, 5+6, 7+8, 9+0)
if (i % 10000 == 0)
system(mem)
}
}
' 2>/dev/null
===============> paste <(./leak.sh ./master.out) <(./leak.sh ./a.out)
2404 2520
4612 2528
6804 2528
9000 2528
11192 2528
13384 2528
15580 2528
17772 2528
19968 2528
22160 2528
24356 2528
--- a/run.c
+++ b/run.c
@@ -1712,8 +1712,10 @@
setfval(x, u);
if (nextarg != NULL) { WARNING("warning: function has too many arguments");- for ( ; nextarg; nextarg = nextarg->nnext)
- execute(nextarg);
+ for ( ; nextarg; nextarg = nextarg->nnext) {+ y = execute(nextarg);
+ tempfree(y);
+ }
}
return(x);
}
--
⑨