I'm running Valgrind:

        $ valgrind --num-callers=20 --leak-check=full --show-reachable=yes 
parrot --leak-test t/pmc/ref_12.pasm

==10213== 60 bytes in 1 blocks are still reachable in loss record 1 of 6
==10213==    at 0x40206D5: calloc (vg_replace_malloc.c:279)
==10213==    by 0x41E822E: mem_sys_allocate_zeroed (memory.c:79)
==10213==    by 0x426C3DD: pt_add_to_interpreters (thread.c:1276)
==10213==    by 0x4268CEB: Parrot_init_events (events.c:313)
==10213==    by 0x41E5D2B: make_interpreter (inter_create.c:245)
==10213==    by 0x424300E: Parrot_new (embed.c:48)
==10213==    by 0x804A433: main (main.c:514)

Here's a patch for that.  Any objections?

I know that everything gets freed with the process ends, but by clearing 
these "leaks" out of the report makes it much more useful for finding actual 
leaks.

-- c

=== include/parrot/thread.h
==================================================================
--- include/parrot/thread.h	(revision 2241)
+++ include/parrot/thread.h	(local)
@@ -167,6 +167,7 @@
 void pt_clone_code(Parrot_Interp d, Parrot_Interp s);
 void pt_clone_globals(Parrot_Interp d, Parrot_Interp s);
 void pt_add_to_interpreters(Parrot_Interp first, Parrot_Interp new_interp);
+void pt_free_interpreter_pool(Parrot_Interp interp);
 void pt_thread_yield(void);
 PMC* pt_thread_join(Parrot_Interp, UINTVAL);
 void pt_thread_detach(UINTVAL);
=== src/inter_create.c
==================================================================
--- src/inter_create.c	(revision 2241)
+++ src/inter_create.c	(local)
@@ -380,6 +380,8 @@
         Parrot_merge_memory_pools(interp->parent_interpreter, interp);
     }
 
+    pt_free_interpreter_pool(interp);
+
     if (interp->arena_base->de_init_gc_system)
         interp->arena_base->de_init_gc_system(interp);
 
=== src/thread.c
==================================================================
--- src/thread.c	(revision 2241)
+++ src/thread.c	(local)
@@ -1318,6 +1318,23 @@
 
 /*
 
+=item C<void pt_free_interpreter_pool(Parrot_Interp interp)>
+
+All threaded interpreters are stored in an array.  Frees this array during
+global destruction.
+
+*/
+
+void
+pt_free_interpreter_pool(Parrot_Interp interp) {
+    Shared_gc_info *info = get_pool(interp);
+
+    if (info != NULL)
+        mem_sys_free(info);
+}
+
+/*
+
 =back
 
 =head2 DOD Synchronization Functions

Reply via email to