[svn:parrot] r39492 - trunk/compilers/imcc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Wed Jun 10 07:28:02 UTC 2009


Author: chromatic
Date: Wed Jun 10 07:28:01 2009
New Revision: 39492
URL: https://trac.parrot.org/parrot/changeset/39492

Log:
[IMCC] Plugged a leak in IMCC where compilation units attached to a namespace
occasionally leaked the IMCC data structure tracking that namespace.  Sometimes
it's the responsibility of the compilation unit to free that namespace;
sometimes it isn't.  Did I mention that IMCC can be opaque?

Modified:
   trunk/compilers/imcc/imc.c
   trunk/compilers/imcc/symreg.c
   trunk/compilers/imcc/unit.h

Modified: trunk/compilers/imcc/imc.c
==============================================================================
--- trunk/compilers/imcc/imc.c	Wed Jun 10 06:47:25 2009	(r39491)
+++ trunk/compilers/imcc/imc.c	Wed Jun 10 07:28:01 2009	(r39492)
@@ -266,6 +266,8 @@
 
     clear_locals(unit);
 
+    if (unit->_namespace && unit->owns_namespace)
+        free_sym(unit->_namespace);
     if (unit->vtable_name)
         mem_sys_free(unit->vtable_name);
     if (unit->instance_of)

Modified: trunk/compilers/imcc/symreg.c
==============================================================================
--- trunk/compilers/imcc/symreg.c	Wed Jun 10 06:47:25 2009	(r39491)
+++ trunk/compilers/imcc/symreg.c	Wed Jun 10 07:28:01 2009	(r39492)
@@ -385,12 +385,18 @@
         SymReg * const g = dup_sym(ns);
         SymReg * const r = _get_sym(&IMCC_INFO(interp)->ghash, g->name);
 
-        unit->_namespace = g;
-        g->reg           = ns;
-        g->type          = VT_CONSTP;
-
-        if (!r || r->type != VT_CONSTP)
+        unit->_namespace     = g;
+        g->reg               = ns;
+        g->type              = VT_CONSTP;
+
+        /* this unit should free its namespace only if it's the only thing
+         * holding onto it */
+        if (!r || r->type != VT_CONSTP) {
             _store_symreg(&IMCC_INFO(interp)->ghash, g);
+            unit->owns_namespace = 0;
+        }
+        else
+            unit->owns_namespace = 1;
     }
 }
 

Modified: trunk/compilers/imcc/unit.h
==============================================================================
--- trunk/compilers/imcc/unit.h	Wed Jun 10 06:47:25 2009	(r39491)
+++ trunk/compilers/imcc/unit.h	Wed Jun 10 07:28:01 2009	(r39492)
@@ -56,6 +56,7 @@
     struct _IMC_Unit *next;
 
     SymReg           *_namespace;
+    int               owns_namespace;   /* should this unit free *_namespace */
     int               pasm_file;
     const char       *file;
     int               n_vars_used[4];   /* INSP in PIR */


More information about the parrot-commits mailing list