[svn:parrot] r39511 - trunk/src/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Thu Jun 11 19:25:12 UTC 2009


Author: chromatic
Date: Thu Jun 11 19:25:10 2009
New Revision: 39511
URL: https://trac.parrot.org/parrot/changeset/39511

Log:
[PMC] Plugged a potential memory leak Coke++ found in the Sub PMC; if a Sub had
no sub attribute, destroy() would never free the allocated attribute storage.
This *should* never happen, but now it will never happen.

Modified:
   trunk/src/pmc/sub.pmc

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc	Thu Jun 11 12:51:08 2009	(r39510)
+++ trunk/src/pmc/sub.pmc	Thu Jun 11 19:25:10 2009	(r39511)
@@ -68,7 +68,7 @@
      */
     VTABLE void init() {
         Parrot_Sub_attributes * const attrs =
-            mem_allocate_zeroed_typed(Parrot_Sub_attributes);
+            mem_allocate_typed(Parrot_Sub_attributes);
 
         attrs->sub     = new_sub(INTERP);
         PMC_data(SELF) = attrs;
@@ -89,16 +89,17 @@
         Parrot_sub *sub;
         GET_ATTR_sub(INTERP, SELF, sub);
 
-        if (!sub)
-            return;
-        if (sub->arg_info)
-            mem_sys_free(sub->arg_info);
-        if (sub->ctx)
-            Parrot_free_context(INTERP, sub->ctx, 1);
-        if (sub->outer_ctx)
-            Parrot_free_context(INTERP, sub->outer_ctx, 1);
+        if (sub) {
+            if (sub->arg_info)
+                mem_sys_free(sub->arg_info);
+            if (sub->ctx)
+                Parrot_free_context(INTERP, sub->ctx, 1);
+            if (sub->outer_ctx)
+                Parrot_free_context(INTERP, sub->outer_ctx, 1);
+
+            mem_sys_free(sub);
+        }
 
-        mem_sys_free(sub);
         mem_sys_free(PMC_data(SELF));
         PMC_data(SELF) = NULL;
     }


More information about the parrot-commits mailing list