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

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Jun 3 09:52:05 UTC 2009


Author: bacek
Date: Wed Jun  3 09:52:03 2009
New Revision: 39351
URL: https://trac.parrot.org/parrot/changeset/39351

Log:
[pmc][cage] Fix memory leak in String.set_string_native.

When we assign to constant string it means that we have to allocate string from
constant pool, not to allocate constant string.

Modified:
   trunk/src/pmc/string.pmc

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc	Wed Jun  3 07:53:28 2009	(r39350)
+++ trunk/src/pmc/string.pmc	Wed Jun  3 09:52:03 2009	(r39351)
@@ -241,8 +241,10 @@
     VTABLE void set_string_native(STRING *value) {
         /* Only allow constant PMCs to embed constant strings */
         if (PObj_constant_TEST(SELF) && !PObj_constant_TEST(value)) {
-             const char *copy = Parrot_str_to_cstring(INTERP, value);
-             value            = Parrot_str_new_constant(INTERP, copy);
+            char *copy = Parrot_str_to_cstring(INTERP, value);
+            value      = Parrot_str_new_init(INTERP, copy, strlen(copy),
+                    PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET, PObj_constant_FLAG);
+            Parrot_str_free_cstring(copy);
         }
 
         SET_ATTR_str_val(INTERP, SELF, value);


More information about the parrot-commits mailing list