awk icon indicating copy to clipboard operation
awk copied to clipboard

awk leaks memory

Open arnoldrobbins opened this issue 4 years ago • 2 comments

After applying the patch in Issue #112 and running valgrind --leak-check=full with the same program, there is a leak:

==5226== Memcheck, a memory error detector ==5226== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==5226== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==5226== Command: ./a.out /^#!\ ?\/.\/[a-z]{0,2}awk/\ {sub(/^#!\ ?\/.\/[a-z]{0,2}awk/,"#!\ awk");\ print} ==5226== #! awk ==5226== ==5226== HEAP SUMMARY: ==5226== in use at exit: 76,019 bytes in 438 blocks ==5226== total heap usage: 541 allocs, 103 frees, 96,472 bytes allocated ==5226== ==5226== 25 bytes in 1 blocks are definitely lost in loss record 79 of 151 ==5226== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5226== by 0x5279AF9: strdup (strdup.c:42) ==5226== by 0x1118D8: tostring (tran.c:535) ==5226== by 0x11BA43: regexpr (lex.c:548) ==5226== by 0x11BF9B: yylex (lex.c:184) ==5226== by 0x10C53E: yyparse (awkgram.tab.c:2257) ==5226== by 0x10BB5E: main (main.c:215) ==5226== ==5226== LEAK SUMMARY: ==5226== definitely lost: 25 bytes in 1 blocks ==5226== indirectly lost: 0 bytes in 0 blocks ==5226== possibly lost: 0 bytes in 0 blocks ==5226== still reachable: 75,994 bytes in 437 blocks ==5226== suppressed: 0 bytes in 0 blocks ==5226== Reachable blocks (those to which a pointer was found) are not shown. ==5226== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==5226== ==5226== For counts of detected and suppressed errors, rerun with: -v ==5226== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Similarly:

$ valgrind --leak-check=full ./a.out \

'BEGIN { x = "a"; sub(/a/, "b", x); print x }' ==5774== Memcheck, a memory error detector ==5774== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==5774== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==5774== Command: ./a.out BEGIN\ {\ x\ =\ "a";\ sub(/a/,\ "b",\ x);\ print\ x\ } ==5774== b ==5774== ==5774== HEAP SUMMARY: ==5774== in use at exit: 40,518 bytes in 348 blocks ==5774== total heap usage: 382 allocs, 34 frees, 54,076 bytes allocated ==5774== ==5774== 1 bytes in 1 blocks are definitely lost in loss record 9 of 110 ==5774== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5774== by 0x5279AF9: strdup (strdup.c:42) ==5774== by 0x1118D8: tostring (tran.c:535) ==5774== by 0x1119B3: setsymtab (tran.c:248) ==5774== by 0x11B2D1: word (lex.c:506) ==5774== by 0x11C533: yylex (lex.c:191) ==5774== by 0x10C53E: yyparse (awkgram.tab.c:2257) ==5774== by 0x10BB5E: main (main.c:215) ==5774== ==5774== LEAK SUMMARY: ==5774== definitely lost: 1 bytes in 1 blocks ==5774== indirectly lost: 0 bytes in 0 blocks ==5774== possibly lost: 0 bytes in 0 blocks ==5774== still reachable: 40,517 bytes in 347 blocks ==5774== suppressed: 0 bytes in 0 blocks ==5774== Reachable blocks (those to which a pointer was found) are not shown. ==5774== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==5774== ==5774== For counts of detected and suppressed errors, rerun with: -v ==5774== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

arnoldrobbins avatar Mar 04 '21 07:03 arnoldrobbins

yes I noticed it too. parse time leak, not critical but annoying. will deal with it shortly.

plan9 avatar Mar 04 '21 15:03 plan9

any news on this?

MaxPeal avatar Apr 05 '22 23:04 MaxPeal

There is a fix from @mpinjr for this in #156

millert avatar Aug 27 '22 01:08 millert