[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gawk] GAWK 4.1.60: Memory Leak in DIV() function
From: |
Katherine Wasserman |
Subject: |
[bug-gawk] GAWK 4.1.60: Memory Leak in DIV() function |
Date: |
Sat, 26 Jul 2014 19:23:29 -0400 |
In version 4.1.60 there appears to be a major memory leak when calling the new
DIV() function.
Running this program (pi.awk):
--------------------------------------------------------------------
BEGIN {
digits = 100000
two=2*(10^digits)
pi=two
for (m=digits*4; m>0; --m)
{d=m*2+1
x=pi*m
div(x,d,result)
pi=result["quotient"]
pi=pi + two
}
print pi
}
--------------------------------------------------------------------
results in all memory (at least 15GB) being used and the program never
completing or crashing.
If you use digits=10000, the program runs fine and completes quickly with the
correct answer.
Removing the call to DIV() avoids the memory leak program but of course doesn't
work, pointing to the near certainty that the problem is with the new DIV()
function and its calls to the MPFR library.
Andy Schorr did some initial debugging with these results:
address@hidden: valgrind --leak-check=full gawk -M -f /tmp/pi.awk
==20008== Memcheck, a memory error detector
==20008== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==20008== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==20008== Command: gawk -M -f /tmp/pi.awk
==20008==
31415926535897932384626433832795028841...
...
(some small memory leaks)
...
==20008== 439,758 bytes in 39,978 blocks are possibly lost in loss record 73 of
76
==20008== at 0x4C28409: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20008== by 0x460C03: make_str_node (node.c:380)
==20008== by 0x45DB15: do_mpfr_div (mpfr.c:1248)
==20008== by 0x4463F3: h_interpret (interpret.h:922)
==20008== by 0x40D0CC: main (main.c:747)
==20008==
==20008== 639,664 bytes in 39,979 blocks are possibly lost in loss record 74 of
76
==20008== at 0x4C2A2F7: realloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20008== by 0x52DD3F3: __gmp_default_reallocate (in
/usr/lib64/libgmp.so.10.1.1)
==20008== by 0x52F1979: __gmpz_realloc (in /usr/lib64/libgmp.so.10.1.1)
==20008== by 0x52E3DF8: __gmpz_add (in /usr/lib64/libgmp.so.10.1.1)
==20008== by 0x45AFBA: mpg_add (mpfr.c:1303)
==20008== by 0x45B809: mpg_interpret (mpfr.c:1480)
==20008== by 0x444F5A: h_interpret (interpret.h:70)
==20008== by 0x40D0CC: main (main.c:747)
==20008==
==20008== 14,080,000 bytes in 1,600 blocks are possibly lost in loss record 75
of 76
==20008== at 0x4C28409: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20008== by 0x4606DC: more_blocks (node.c:978)
==20008== by 0x45A8F9: mpg_node (mpfr.c:98)
==20008== by 0x45DA77: do_mpfr_div (mpfr.c:1235)
==20008== by 0x4463F3: h_interpret (interpret.h:922)
==20008== by 0x40D0CC: main (main.c:747)
==20008==
==20008== 166,632,472 bytes in 39,979 blocks are possibly lost in loss record
76 of 76
==20008== at 0x4C2A2F7: realloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==20008== by 0x52DD3F3: __gmp_default_reallocate (in
/usr/lib64/libgmp.so.10.1.1)
==20008== by 0x52F1979: __gmpz_realloc (in /usr/lib64/libgmp.so.10.1.1)
==20008== by 0x52EE6B3: __gmpz_mul (in /usr/lib64/libgmp.so.10.1.1)
==20008== by 0x45B11A: mpg_mul (mpfr.c:1361)
==20008== by 0x45B77D: mpg_interpret (mpfr.c:1508)
==20008== by 0x444F5A: h_interpret (interpret.h:70)
==20008== by 0x40D0CC: main (main.c:747)
==20008==
==20008== LEAK SUMMARY:
==20008== definitely lost: 0 bytes in 0 blocks
==20008== indirectly lost: 0 bytes in 0 blocks
==20008== possibly lost: 182,195,854 bytes in 161,516 blocks
==20008== still reachable: 138,782 bytes in 242 blocks
==20008== suppressed: 0 bytes in 0 blocks
==20008== Reachable blocks (those to which a pointer was found) are not shown.
==20008== To see them, rerun with: --leak-check=full --show-reachable=yes
==20008==
==20008== For counts of detected and suppressed errors, rerun with: -v
==20008== ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 2 from 2)
Thanks,
Katie
- [bug-gawk] GAWK 4.1.60: Memory Leak in DIV() function,
Katherine Wasserman <=