[svn:parrot] r39675 - in trunk/src: gc interp pmc

Infinoid at svn.parrot.org Infinoid at svn.parrot.org
Sat Jun 20 20:24:19 UTC 2009


Author: Infinoid
Date: Sat Jun 20 20:24:17 2009
New Revision: 39675
URL: https://trac.parrot.org/parrot/changeset/39675

Log:
Fix 3 thread-related leaks.
1.  Fix a leak in ParrotRunningThread.  The attrs array was allocated but never freed, because the active_destroy flag wasn't set.
2.  Parrot_gc_add_pmc_sync() allocates a new PMC_sync() value without checking to see if one already existed.  Add a check, only call it when we don't already have one.
3.  Parrot_really_destroy() did not free the vtables[] array in the case where interp->parent_interpreter was set.  The vtables array is per-thread, so it needs to be freed regardless.  Whiteknight++ for finding this one.

In a simple pir test (based on the tt757 test case) which created and joined a thread 200 times, this patch fixes 62 megs of leaked memory.

Modified:
   trunk/src/gc/api.c
   trunk/src/interp/inter_create.c
   trunk/src/pmc/parrotinterpreter.pmc
   trunk/src/pmc/parrotrunningthread.pmc
   trunk/src/pmc/parrotthread.pmc

Modified: trunk/src/gc/api.c
==============================================================================
--- trunk/src/gc/api.c	Sat Jun 20 14:09:03 2009	(r39674)
+++ trunk/src/gc/api.c	Sat Jun 20 20:24:17 2009	(r39675)
@@ -394,6 +394,9 @@
     ASSERT_ARGS(Parrot_gc_add_pmc_sync)
     if (!PObj_is_PMC_EXT_TEST(pmc))
         Parrot_gc_add_pmc_ext(interp, pmc);
+    if (PMC_sync(pmc))
+        /* This mutex already exists, leave it alone. */
+        return;
     PMC_sync(pmc) = mem_allocate_typed(Sync);
     if (!PMC_sync(pmc))
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ALLOCATION_ERROR,

Modified: trunk/src/interp/inter_create.c
==============================================================================
--- trunk/src/interp/inter_create.c	Sat Jun 20 14:09:03 2009	(r39674)
+++ trunk/src/interp/inter_create.c	Sat Jun 20 20:24:17 2009	(r39675)
@@ -466,6 +466,7 @@
                 interp->thread_data = NULL;
             }
 
+            parrot_free_vtables(interp);
             mem_sys_free(interp);
         }
     }

Modified: trunk/src/pmc/parrotinterpreter.pmc
==============================================================================
--- trunk/src/pmc/parrotinterpreter.pmc	Sat Jun 20 14:09:03 2009	(r39674)
+++ trunk/src/pmc/parrotinterpreter.pmc	Sat Jun 20 20:24:17 2009	(r39675)
@@ -242,8 +242,8 @@
             PMC_data(SELF) = attrs;
             create_interp(SELF, INTERP);
             PARROT_ASSERT(attrs->interp);
-            PObj_active_destroy_SET(SELF);
         }
+        PObj_active_destroy_SET(SELF);
     }
 
 /*

Modified: trunk/src/pmc/parrotrunningthread.pmc
==============================================================================
--- trunk/src/pmc/parrotrunningthread.pmc	Sat Jun 20 14:09:03 2009	(r39674)
+++ trunk/src/pmc/parrotrunningthread.pmc	Sat Jun 20 20:24:17 2009	(r39675)
@@ -50,6 +50,7 @@
             mem_allocate_zeroed_typed(Parrot_ParrotRunningThread_attributes);
         attrs->tid = -1;
         PMC_data(SELF) = attrs;
+        PObj_active_destroy_SET(SELF);
     }
 
 /*

Modified: trunk/src/pmc/parrotthread.pmc
==============================================================================
--- trunk/src/pmc/parrotthread.pmc	Sat Jun 20 14:09:03 2009	(r39674)
+++ trunk/src/pmc/parrotthread.pmc	Sat Jun 20 20:24:17 2009	(r39675)
@@ -70,7 +70,6 @@
 
     pmc_reuse(interp, thread, enum_class_ParrotRunningThread, 0);
 
-    PObj_active_destroy_CLEAR(thread);
     PObj_custom_mark_CLEAR(thread);
     VTABLE_set_integer_native(interp, thread, tid);
 


More information about the parrot-commits mailing list