Author: chromatic
Date: Fri Apr 20 20:37:21 2007
New Revision: 18293

Modified:
   trunk/compilers/imcc/pbc.c
   trunk/include/parrot/string_funcs.h
   trunk/src/objects.c
   trunk/src/string.c

Log:
Fixed two memory leaks related to not freeing C strings appropriately.

This prevents almost 4.5 megabytes of leaks from t/compilers/pge/p5regex/p5rx.t.

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c  (original)
+++ trunk/compilers/imcc/pbc.c  Fri Apr 20 20:37:21 2007
@@ -737,8 +737,10 @@
             vtable_name = sub->name;
 
         /* Check this is a valid vtable method to override. */
-        c_name = string_to_cstring(interp, vtable_name);
+        c_name       = string_to_cstring(interp, vtable_name);
         vtable_index = Parrot_get_vtable_index(interp, c_name);
+        string_cstring_free(c_name);
+
         if (vtable_index == -1) {
             IMCC_fatal(interp, 1,
                 "'%s' is not a v-table method, but was used with :vtable.\n",

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h (original)
+++ trunk/include/parrot/string_funcs.h Fri Apr 20 20:37:21 2007
@@ -83,7 +83,7 @@
 PARROT_API STRING *const_string(Interp *, const char *buffer)
         __attribute__nonnull__(2);
 PARROT_API char *string_to_cstring(Interp *, STRING *);
-PARROT_API void string_cstring_free(void *);
+PARROT_API void string_cstring_free(char *);
 PARROT_API void string_pin(Interp *, STRING *);
 PARROT_API void string_unpin(Interp *, STRING *);
 PARROT_API STRING *string_bitwise_and(Interp *interp, STRING *s1,

Modified: trunk/src/objects.c
==============================================================================
--- trunk/src/objects.c (original)
+++ trunk/src/objects.c Fri Apr 20 20:37:21 2007
@@ -54,15 +54,17 @@
 
 PMC*
 Parrot_find_vtable_meth(Interp* interp, PMC *pmc, STRING *meth) {
-    PMC *_class = pmc;
-    PMC *ns = NULL;
-    PMC *mro;
-    PMC *key;
+    PMC  *_class = pmc;
+    PMC  *ns     = NULL;
+    PMC  *mro;
+    PMC  *key;
+    char *slot_name;
     INTVAL i, n, j, k;
 
     /* Get index in Parrot_vtable_slot_names[]. */
-    int vtable_index = Parrot_get_vtable_index(interp,
-        string_to_cstring(interp, meth));
+    slot_name        = string_to_cstring(interp, meth);
+    int vtable_index = Parrot_get_vtable_index(interp, slot_name);
+    string_cstring_free(slot_name);
     if (vtable_index == -1)
       return NULL;
 

Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c  (original)
+++ trunk/src/string.c  Fri Apr 20 20:37:21 2007
@@ -1880,9 +1880,9 @@
 */
 
 void
-string_cstring_free(void *ptr)
+string_cstring_free(char *p)
 {
-    mem_sys_free(ptr);
+    mem_sys_free(p);
 }
 
 /*

Reply via email to