petdance/scratch — Issue #429: Memory leak in compile_file functions
Author: petdance
Created: 2011-11-01 04:26:00+00:00
State: open

{{{
$ valgrind --leak-check=full ./parrot t/compilers/tge/basic.t
==29055== Memcheck, a memory error detector
==29055== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==29055== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==29055== Command: ./parrot t/compilers/tge/basic.t
==29055==
1..11
ok 1 - build up a basic rule in a grammar
ok 2 - build up a basic rule in a grammar
ok 3 - build up a basic rule in a grammar
ok 4 - agid hash
ok 5 - agid hash
ok 6 - agid hash
ok 7 - agid hash
ok 8 - agid hash
ok 9 - agid hash
ok 10 - agid hash
ok 11 - "Malformed string" in r11890 under Linux i386
==29055==
==29055== HEAP SUMMARY:
==29055== in use at exit: 2,439,605 bytes in 6,345 blocks
==29055== total heap usage: 12,953 allocs, 6,608 frees, 2,790,512 bytes allocated
==29055==
==29055== 2,044 (12 direct, 2,032 indirect) bytes in 1 blocks are definitely lost in loss record 918 of 1,129
==29055== at 0x4023796: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==29055== by 0x410CA3B: gc_gms_allocate_memory_chunk_zeroed (gc_gms.c:1854)
==29055== by 0x4102D57: Parrot_gc_allocate_memory_chunk_with_interior_pointers (api.c:667)
==29055== by 0x4268E26: e_pbc_open (pbc.c:455)
==29055== by 0x425F587: emit_open (instructions.c:671)
==29055== by 0x425953D: imcc_compile_buffer_safe (imcc.l:1370)
==29055== by 0x425AF27: imcc_run_compilation_internal (main.c:574)
==29055== by 0x425AD63: imcc_run_compilation_reentrant (main.c:527)
==29055== by 0x425ACC6: imcc_compile_file (main.c:504)
==29055== by 0x41F5E7B: Parrot_IMCCompiler_nci_compile_file (imccompiler.c:372)
==29055== by 0x41FD24E: Parrot_NativePCCMethod_invoke (nativepccmethod.c:124)
==29055== by 0x4117888: Parrot_pcc_invoke_from_sig_object (pcc.c:329)
==29055==
==29055== 4,589 (12 direct, 4,577 indirect) bytes in 1 blocks are definitely lost in loss record 1,069 of 1,129
==29055== at 0x4023796: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==29055== by 0x410CA3B: gc_gms_allocate_memory_chunk_zeroed (gc_gms.c:1854)
==29055== by 0x4102D57: Parrot_gc_allocate_memory_chunk_with_interior_pointers (api.c:667)
==29055== by 0x4268E26: e_pbc_open (pbc.c:455)
==29055== by 0x425F587: emit_open (instructions.c:671)
==29055== by 0x425953D: imcc_compile_buffer_safe (imcc.l:1370)
==29055== by 0x425AF27: imcc_run_compilation_internal (main.c:574)
==29055== by 0x425AD63: imcc_run_compilation_reentrant (main.c:527)
==29055== by 0x425ACC6: imcc_compile_file (main.c:504)
==29055== by 0x411D6A5: Parrot_compile_file (inter_misc.c:243)
==29055== by 0x4156E87: compile_file (api.c:1983)
==29055== by 0x4157858: Parrot_load_bytecode (api.c:2218)
==29055==
==29055== LEAK SUMMARY:
==29055== definitely lost: 24 bytes in 2 blocks
==29055== indirectly lost: 6,609 bytes in 140 blocks
==29055== possibly lost: 0 bytes in 0 blocks
==29055== still reachable: 2,432,972 bytes in 6,203 blocks
==29055== suppressed: 0 bytes in 0 blocks
==29055== Reachable blocks (those to which a pointer was found) are not shown.
==29055== To see them, rerun with: --leak-check=full --show-reachable=yes
==29055==
==29055== For counts of detected and suppressed errors, rerun with: -v
==29055== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 37 from 8)
}}}

The mem leak happens in

{{{
e_pbc_open(pbc.c:455): imcc->globals = mem_gc_allocate_zeroed_typed(imcc->interp, imcc_globals);
}}}