diff options
author | Miguel Pineiro Jr <mpj@pineiro.cc> | 2022-08-30 14:43:34 -0400 |
---|---|---|
committer | Miguel Pineiro Jr <mpj@pineiro.cc> | 2022-08-30 18:46:32 -0400 |
commit | 4da7f6957e1934deaea782b653e6242713d2a9b6 (patch) | |
tree | a42884649125d2f5c8de5eb8dce38b94eb21eda3 | |
parent | 13cb1f4bb3a03bf42eba8cbe52f2b83c11774807 (diff) | |
download | one-true-awk-4da7f6957e1934deaea782b653e6242713d2a9b6.tar.gz |
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
-rw-r--r-- | run.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1712,8 +1712,10 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis 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); } |