Author: chromatic
Date: Fri Apr 20 21:54:51 2007
New Revision: 18294

Modified:
   trunk/compilers/bcg/src/pmc/bcg.pmc
   trunk/compilers/imcc/main.c
   trunk/compilers/imcc/parser_util.c
   trunk/compilers/imcc/pbc.c
   trunk/src/dynpmc/gdbmhash.pmc
   trunk/src/extend.c
   trunk/src/headers.c
   trunk/src/jit_debug.c
   trunk/src/jit_debug_xcoff.c
   trunk/src/library.c
   trunk/src/ops/debug.ops
   trunk/src/ops/io.ops
   trunk/src/ops/object.ops
   trunk/src/ops/pmc.ops
   trunk/src/packfile.c
   trunk/src/pmc/delegate.pmc
   trunk/src/pmc/env.pmc
   trunk/src/pmc/namespace.pmc
   trunk/src/pmc/os.pmc
   trunk/src/pmc/parrotio.pmc
   trunk/src/sub.c
   trunk/src/utils.c

Log:
Free strings allocated with string_to_cstring().

Minor code formatting cleanups while I made you recompile anyway.

Note that this causes some const-loss warnings (which I don't know how to fix). 

Also, I'm not sure if the declarations and assignments are legal on really 
picky compilers, so they may need adjusting.

Modified: trunk/compilers/bcg/src/pmc/bcg.pmc
==============================================================================
--- trunk/compilers/bcg/src/pmc/bcg.pmc (original)
+++ trunk/compilers/bcg/src/pmc/bcg.pmc Fri Apr 20 21:54:51 2007
@@ -130,8 +130,11 @@
 
         bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_start_sub(bcg_info, string_to_cstring(INTERP, subName),
-                string_to_cstring(INTERP, pragma));
+            char *name_str   = string_to_cstring(INTERP, subName);
+            char *pragma_str = string_to_cstring(INTERP, pragma).
+            BCG_start_sub(bcg_info, name_str, pragma_str);
+            string_cstring_free(name_str);
+            string_cstring_free(pragma_str);
         }
         BCG_CATCH(BCG_EXCEPTION) {
              real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
@@ -176,7 +179,9 @@
 
         bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_start_call(bcg_info, string_to_cstring(INTERP, subName));
+            char *name_str = string_to_cstring(INTERP, subName);
+            BCG_start_call(bcg_info, name_str);
+            string_cstring_free(name_str);
         }
         BCG_CATCH(BCG_EXCEPTION) {
              real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
@@ -222,7 +227,9 @@
 
         bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_start_op(bcg_info, string_to_cstring(INTERP, op));
+            char *op_name = string_to_cstring(INTERP, op);
+            BCG_start_op(bcg_info, op_name);
+            string_cstring_free(op_name);
         }
         BCG_CATCH(BCG_EXCEPTION) {
              real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
@@ -265,18 +272,26 @@
     METHOD void val(STRING *value, STRING *type)
     {
         BCG_info *bcg_info;
-        char data_type;
+        char      data_type;
+        char     *type_str = string_to_cstring(INTERP, type);
+        char     *val_str  = string_to_cstring(INTERP, value);
+
+        data_type = get_data_type_from_cstring(INTERP, type_str);
+        bcg_info  = (BCG_info*) PMC_struct_val(SELF);
+
+        string_cstring_free(type_str);
 
-        data_type = get_data_type_from_cstring(INTERP,
-                                            string_to_cstring(INTERP, type));
-        bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_val(bcg_info, string_to_cstring(INTERP, value), data_type);
+            BCG_val(bcg_info, val_str, data_type);
         }
         BCG_CATCH(BCG_EXCEPTION) {
-             real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
+            string_cstring_free(val_str);
+            real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
         }
         BCG_END_TRY;
+
+        if (val_str)
+            string_cstring_free(val_str);
     }
 
 /*
@@ -291,18 +306,25 @@
     METHOD void var(STRING *varName, STRING *type)
     {
         BCG_info *bcg_info;
-        char data_type;
+        char      data_type;
+        char     *type_str = string_to_cstring(INTERP, type);
+        char     *name_str = string_to_cstring(INTERP, varName);
+
+        data_type = get_data_type_from_cstring(INTERP, type_str);
+        bcg_info  = (BCG_info*) PMC_struct_val(SELF);
+        string_cstring_free(type_str);
 
-        data_type = get_data_type_from_cstring(INTERP,
-                                            string_to_cstring(INTERP, type));
-        bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_var(bcg_info, string_to_cstring(INTERP, varName), data_type);
+            BCG_var(bcg_info, name_str, data_type);
         }
         BCG_CATCH(BCG_EXCEPTION) {
-             real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
+            string_cstring_free(name_str);
+            real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
         }
         BCG_END_TRY;
+
+        if (name_str)
+            string_cstring_free(name_str);
     }
 
 /*
@@ -317,15 +339,20 @@
     METHOD void label(STRING *label)
     {
         BCG_info *bcg_info;
+        char     *label_str = string_to_cstring(INTERP, label);
 
         bcg_info = (BCG_info*) PMC_struct_val(SELF);
         BCG_TRY(bcg_info) {
-            BCG_label(bcg_info, string_to_cstring(INTERP, label));
+            BCG_label(bcg_info, label_str);
         }
         BCG_CATCH(BCG_EXCEPTION) {
-             real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
+            string_cstring_free(label_str);
+            real_exception(INTERP, NULL, E_Exception, bcg_info->error_msg);
         }
         BCG_END_TRY;
+
+        if (label_str)
+            string_cstring_free(label_str);
     }
 
 

Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c (original)
+++ trunk/compilers/imcc/main.c Fri Apr 20 21:54:51 2007
@@ -709,19 +709,23 @@
             imc_compile_all_units(interp);
         }
         IMCC_CATCH(IMCC_FATAL_EXCEPTION) {
+            char *error_str = string_to_cstring(interp,
+                    IMCC_INFO(interp)->error_message);
+
             IMCC_INFO(interp)->error_code=IMCC_FATAL_EXCEPTION;
-            fprintf(stderr,"error:imcc:%s",
-                    string_to_cstring(interp,
-                    IMCC_INFO(interp)->error_message));
+            fprintf(stderr,"error:imcc:%s", error_str);
             IMCC_print_inc(interp);
+            string_cstring_free(error_str);
             Parrot_exit(interp, IMCC_FATAL_EXCEPTION);
         }
         IMCC_CATCH(IMCC_FATALY_EXCEPTION) {
+            char *error_str = string_to_cstring(interp,
+                    IMCC_INFO(interp)->error_message);
+
             IMCC_INFO(interp)->error_code=IMCC_FATALY_EXCEPTION;
-            fprintf(stderr,"error:imcc:%s",
-                    string_to_cstring(interp,
-                    IMCC_INFO(interp)->error_message));
+            fprintf(stderr,"error:imcc:%s", error_str);
             IMCC_print_inc(interp);
+            string_cstring_free(error_str);
             Parrot_exit(interp, IMCC_FATALY_EXCEPTION);
         }
         IMCC_END_TRY;

Modified: trunk/compilers/imcc/parser_util.c
==============================================================================
--- trunk/compilers/imcc/parser_util.c  (original)
+++ trunk/compilers/imcc/parser_util.c  Fri Apr 20 21:54:51 2007
@@ -728,12 +728,14 @@
 imcc_compile_pasm_ex(Parrot_Interp interp, const char *s)
 {
     STRING *error_message;
-    PMC *sub;
+    PMC    *sub;
+    char   *error_str;
 
     sub = imcc_compile(interp, s, 1, &error_message);
     if (sub == NULL ) {
-        real_exception(interp, NULL, E_Exception,
-              string_to_cstring(interp, error_message));
+        error_str = string_to_cstring(interp, error_message);
+        real_exception(interp, NULL, E_Exception, error_str);
+        string_cstring_free(error_str);
     }
     return sub;
 }
@@ -742,12 +744,14 @@
 imcc_compile_pir_ex(Parrot_Interp interp, const char *s)
 {
     STRING *error_message;
-    PMC *sub;
+    PMC    *sub;
+    char   *error_str;
 
     sub = imcc_compile(interp, s, 0, &error_message);
     if (sub == NULL) {
-        real_exception(interp, NULL, E_Exception,
-              string_to_cstring(interp, error_message));
+        error_str = string_to_cstring(interp, error_message);
+        real_exception(interp, NULL, E_Exception, error_str);
+        string_cstring_free(error_str);
     }
     return sub;
 }

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c  (original)
+++ trunk/compilers/imcc/pbc.c  Fri Apr 20 21:54:51 2007
@@ -739,13 +739,13 @@
         /* Check this is a valid vtable method to override. */
         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",
                 c_name);
         }
+        string_cstring_free(c_name);
 
         /* TODO check for duplicates */
         sub->vtable_index = vtable_index;

Modified: trunk/src/dynpmc/gdbmhash.pmc
==============================================================================
--- trunk/src/dynpmc/gdbmhash.pmc       (original)
+++ trunk/src/dynpmc/gdbmhash.pmc       Fri Apr 20 21:54:51 2007
@@ -118,8 +118,10 @@
 */
 
     void set_string_native(STRING* value) {
-        char *c_db_name = string_to_cstring(INTERP, value);
-        GDBM_FILE dbf = gdbm_open(c_db_name, 0, GDBM_NEWDB, 0666, 0);
+        char *c_db_name      = string_to_cstring(INTERP, value);
+        GDBM_FILE dbf        = gdbm_open(c_db_name, 0, GDBM_NEWDB, 0666, 0);
+
+        string_cstring_free(c_db_name);
 
         PMC_struct_val(SELF) = dbf;
     }

Modified: trunk/src/extend.c
==============================================================================
--- trunk/src/extend.c  (original)
+++ trunk/src/extend.c  Fri Apr 20 21:54:51 2007
@@ -233,18 +233,23 @@
 
 Return a null-terminated string that represents the string value of the PMC.
 
+Note that you must free this string with C<string_cstring_free()>!
+
 =cut
 
 */
 
-char *Parrot_PMC_get_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
+char *
+Parrot_PMC_get_cstring_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
                                     Parrot_Int key) {
     STRING *intermediate;
-    char *retval;
+    char   *retval;
+
     PARROT_CALLIN_START(interp);
     intermediate = VTABLE_get_string_keyed_int(interp, pmc, key);
-    retval =  string_to_cstring(interp, intermediate);
+    retval       = string_to_cstring(interp, intermediate);
     PARROT_CALLIN_END(interp);
+
     return retval;
 }
 
@@ -254,17 +259,22 @@
 
 Return a null-terminated string that represents the string value of the PMC.
 
+Note that you must free this string with C<string_cstring_free()>!
+
 =cut
 
 */
 
-char *Parrot_PMC_get_cstring(Parrot_INTERP interp, Parrot_PMC pmc) {
+char *
+Parrot_PMC_get_cstring(Parrot_INTERP interp, Parrot_PMC pmc) {
     STRING *intermediate;
-    char *retval;
+    char   *retval;
+
     PARROT_CALLIN_START(interp);
     intermediate = VTABLE_get_string(interp, pmc);
-    retval = string_to_cstring(interp, intermediate);
+    retval       = string_to_cstring(interp, intermediate);
     PARROT_CALLIN_END(interp);
+
     return retval;
 }
 
@@ -279,17 +289,22 @@
 Yes, right now this is a bit of a cheat. It needs fixing, but without
 disturbing the interface.
 
+Note that you must free the string with C<string_cstring_free()>.
+
 =cut
 
 */
 
-char *Parrot_PMC_get_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
+char *
+Parrot_PMC_get_cstringn(Parrot_INTERP interp, Parrot_PMC pmc,
                               Parrot_Int *length) {
     char *retval;
+
     PARROT_CALLIN_START(interp);
-    retval = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
+    retval  = string_to_cstring(interp, VTABLE_get_string(interp, pmc));
     *length = strlen(retval);
     PARROT_CALLIN_END(interp);
+
     return retval;
 }
 
@@ -304,18 +319,23 @@
 Yes, right now this is a bit of a cheat. It needs fixing, but without
 disturbing the interface.
 
+Note that you must free this string with C<string_cstring_free()>.
+
 =cut
 
 */
 
-char *Parrot_PMC_get_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
+char *
+Parrot_PMC_get_cstringn_intkey(Parrot_INTERP interp, Parrot_PMC pmc,
                                      Parrot_Int *length, Parrot_Int key) {
     char *retval;
+
     PARROT_CALLIN_START(interp);
-    retval = string_to_cstring(interp,
+    retval  = string_to_cstring(interp,
                                VTABLE_get_string_keyed_int(interp, pmc, key));
     *length = strlen(retval);
     PARROT_CALLIN_END(interp);
+
     return retval;
 }
 

Modified: trunk/src/headers.c
==============================================================================
--- trunk/src/headers.c (original)
+++ trunk/src/headers.c Fri Apr 20 21:54:51 2007
@@ -746,6 +746,7 @@
 }
 
 /*
+
 =item C<void
 Parrot_merge_header_pools(Interp *dest_interp, Interp *source_interp)>
 
@@ -753,6 +754,7 @@
 (Used to deal with shared objects left after interpreter destruction.)
 
 =cut
+
 */
 
 static void fix_pmc_syncs(Interp *dest_interp, Small_Object_Pool *pool) {

Modified: trunk/src/jit_debug.c
==============================================================================
--- trunk/src/jit_debug.c       (original)
+++ trunk/src/jit_debug.c       Fri Apr 20 21:54:51 2007
@@ -300,6 +300,8 @@
         else if (!ext) /* EVAL_n */
             file = string_append(interp, file,
                     string_make(interp, ".", 1, NULL, PObj_external_FLAG));
+
+        string_cstring_free(src);
     }
     else {
         /* chop pbc */
@@ -307,11 +309,11 @@
         pasmfile = debug_file(interp, file, "pasm");
     }
     stabsfile = debug_file(interp, file, "stabs.s");
-    ofile = debug_file(interp, file, "o");
+    ofile     = debug_file(interp, file, "o");
     {
         char *temp = string_to_cstring(interp,stabsfile);
-        stabs = fopen(temp, "w");
-        free(temp);
+        stabs      = fopen(temp, "w");
+        string_cstring_free(temp);
     }
     if (stabs == NULL)
         return;
@@ -321,7 +323,7 @@
         /* filename info */
         fprintf(stabs, ".data\n.text\n");       /* darwin wants it */
         fprintf(stabs, ".stabs \"%s\"," N_SO ",0,0,0\n",temp);
-        free(temp);
+        string_cstring_free(temp);
     }
     /* jit_func start addr */
     fprintf(stabs, ".stabs \"jit_func:F(0,1)\"," N_FUN ",0,1,%p\n",
@@ -364,7 +366,7 @@
     {
         char *temp = string_to_cstring(interp, cmd);
         system(temp);
-        free(temp);
+        string_cstring_free(temp);
     }
 }
 

Modified: trunk/src/jit_debug_xcoff.c
==============================================================================
--- trunk/src/jit_debug_xcoff.c (original)
+++ trunk/src/jit_debug_xcoff.c Fri Apr 20 21:54:51 2007
@@ -269,6 +269,7 @@
         else if (!ext) /* EVAL_n */
             file = string_append(interp, file,
                     string_make(interp, ".", 1, NULL, PObj_external_FLAG));
+        string_cstring_free(src);
     }
     else {
         /* chop pbc */
@@ -279,8 +280,8 @@
     ofile = debug_file(interp, file, "o");
     {
         char *temp = string_to_cstring(interp,stabsfile);
-        stabs = fopen(temp, "w");
-        free(temp);
+        stabs      = fopen(temp, "w");
+        string_cstring_free(temp);
     }
     if (stabs == NULL)
         return;
@@ -289,7 +290,7 @@
         char *temp = string_to_cstring(interp, pasmfile);
         /* filename info */
         fprintf(stabs, ".file \"%s\"\n",temp);
-        free(temp);
+        string_cstring_free(temp);
     }
     /* declare function name */
     fprintf(stabs, ".jit_func:\n");
@@ -334,7 +335,7 @@
     {
         char *temp = string_to_cstring(interp, cmd);
         system(temp);
-        free(temp);
+        string_cstring_free(temp);
     }
 }
 

Modified: trunk/src/library.c
==============================================================================
--- trunk/src/library.c (original)
+++ trunk/src/library.c Fri Apr 20 21:54:51 2007
@@ -263,7 +263,7 @@
 
 Locate the full path for C<file_name> and the given file type(s). If
 successful, returns a C-string allocated with C<string_to_cstring> or
-NULL otherwise.
+NULL otherwise.  Remember to free the string with C<string_cstring_free()>.
 
 =item C<STRING* Parrot_locate_runtime_file_str(Interp *, STRING  *file_name,
         enum_runtime_ft type)>
@@ -347,8 +347,9 @@
 
 =item C<const char* Parrot_get_runtime_prefix(Interp *, STRING **prefix_str)>
 
-If C<prefix_str> is not NULL, set it to the prefix, else
-return a malloced c-string for the runtime prefix.
+If C<prefix_str> is not NULL, set it to the prefix, else return a malloced
+c-string for the runtime prefix.  Remember to free the string with
+C<string_cstring_free()>.
 
 =cut
 

Modified: trunk/src/ops/debug.ops
==============================================================================
--- trunk/src/ops/debug.ops     (original)
+++ trunk/src/ops/debug.ops     Fri Apr 20 21:54:51 2007
@@ -66,6 +66,7 @@
     if (!(interp->pdb->state & PDB_BREAK)) {
         f = string_to_cstring(interp,($1));
         PDB_load_source(interp,f);
+        string_cstring_free(f);
     }
 
     goto NEXT();

Modified: trunk/src/ops/io.ops
==============================================================================
--- trunk/src/ops/io.ops        (original)
+++ trunk/src/ops/io.ops        Fri Apr 20 21:54:51 2007
@@ -53,19 +53,21 @@
 =cut
 
 inline op fdopen(out PMC, in INT, in STR) :filesys_open {
-  /* These char * need to go away soon */
-  const char * const mode = string_to_cstring(interp, $3);
+    /* These char * need to go away soon */
+    char * const mode = string_to_cstring(interp, $3);
 
-  $1 = PIO_fdopen(interp, NULL, (PIOHANDLE)$2, mode);
-  if (!$1) {
-    $1 = pmc_new(interp, enum_class_Undef);
-  }
-  /* string_cstring_free(mode); */
-  /* RT#42374 all results from string_to_cstring() need freeing
+    $1 = PIO_fdopen(interp, NULL, (PIOHANDLE)$2, mode);
+    if (!$1)
+        $1 = pmc_new(interp, enum_class_Undef);
+
+    /* RT#42374 all results from string_to_cstring() need freeing
      but this generates ugly warnings WRT discarding the const
      qualifier -lt
-   */
-  goto NEXT();
+    */
+
+    string_cstring_free(mode);
+
+    goto NEXT();
 }
 
 =item B<getfd>(out INT, invar PMC)
@@ -170,29 +172,31 @@
 =cut
 
 inline op open(out PMC, in STR, in STR) :filesys_open {
-  /* These char * need to go away soon */
-  const char * const path = string_to_cstring(interp, $2);
-  const char * const mode = string_to_cstring(interp, $3);
-
-  $1 = PIO_open(interp, NULL, path, mode);
-  /* string_cstring_free(mode); */
-  /* string_cstring_free(path); */
-  if (!$1 || !PMC_struct_val($1)) {
-    $1 = pmc_new(interp, enum_class_Undef);
-  }
-  goto NEXT();
+    /* These char * need to go away soon */
+    char * const path = string_to_cstring(interp, $2);
+    char * const mode = string_to_cstring(interp, $3);
+
+    $1 = PIO_open(interp, NULL, path, mode);
+
+    string_cstring_free(mode);
+    string_cstring_free(path);
+
+    if (!$1 || !PMC_struct_val($1))
+        $1 = pmc_new(interp, enum_class_Undef);
+
+    goto NEXT();
 }
 
 inline op open(out PMC, in STR) :filesys_open {
-  /* These char * need to go away soon */
-  const char * const path = string_to_cstring(interp, $2);
+    /* These char * need to go away soon */
+    char * const path = string_to_cstring(interp, $2);
 
-  $1 = PIO_open(interp, NULL, path, "+<");
-  /* string_cstring_free(path); */
-  if (!$1) {
-    $1 = pmc_new(interp, enum_class_Undef);
-  }
-  goto NEXT();
+    $1 = PIO_open(interp, NULL, path, "+<");
+    string_cstring_free(path);
+    if (!$1)
+        $1 = pmc_new(interp, enum_class_Undef);
+
+    goto NEXT();
 }
 
 ########################################

Modified: trunk/src/ops/object.ops
==============================================================================
--- trunk/src/ops/object.ops    (original)
+++ trunk/src/ops/object.ops    Fri Apr 20 21:54:51 2007
@@ -345,14 +345,17 @@
 }
 
 op subclass(out PMC, in STR, in PMC) :object_classes {
-  PMC *_class = Parrot_class_lookup(interp, $2);
-  opcode_t *next = expr NEXT();
-  if (PMC_IS_NULL(_class)) {
-    real_exception(interp, next, NO_CLASS, "Class '%s' doesn't exist",
-                string_to_cstring(interp, $2));
-  }
-  $1 = VTABLE_subclass(interp, _class, $3);
-  goto ADDRESS(next);
+    PMC      *_class = Parrot_class_lookup(interp, $2);
+    opcode_t *next   = expr NEXT();
+
+    if (PMC_IS_NULL(_class)) {
+        char *class_name = string_to_cstring(interp, $2);
+        real_exception(interp, next, NO_CLASS, "Class '%s' doesn't exist",
+                class_name);
+    }
+
+    $1 = VTABLE_subclass(interp, _class, $3);
+    goto ADDRESS(next);
 }
 
 ###############################################################################
@@ -367,14 +370,17 @@
 =cut
 
 inline op getclass(out PMC, in STR) :object_classes {
-  PMC *_class = Parrot_class_lookup(interp, $2);
-  opcode_t *next = expr NEXT();
-  if (PMC_IS_NULL(_class)) {
-    real_exception(interp, next, NO_CLASS, "Class '%s' doesn't exist",
-                string_to_cstring(interp, $2));
-  }
-  else
-    $1 = _class;
+    PMC      *_class = Parrot_class_lookup(interp, $2);
+    opcode_t *next   = expr NEXT();
+
+    if (PMC_IS_NULL(_class)) {
+        char *class_name = string_to_cstring(interp, $2);
+        real_exception(interp, next, NO_CLASS, "Class '%s' doesn't exist",
+                class_name);
+    }
+    else
+        $1 = _class;
+
   goto ADDRESS(next);
 }
 

Modified: trunk/src/ops/pmc.ops
==============================================================================
--- trunk/src/ops/pmc.ops       (original)
+++ trunk/src/ops/pmc.ops       Fri Apr 20 21:54:51 2007
@@ -270,9 +270,12 @@
 op find_method(out PMC, invar PMC, in STR) {
     opcode_t * resume = expr NEXT();
     $1 = $2->vtable->find_method(interp, $2, $3);
-    if (!$1 || !VTABLE_defined(interp, $1))
+    if (!$1 || !VTABLE_defined(interp, $1)) {
+        char *method_name = string_to_cstring(interp, $3);
         real_exception(interp, resume, METH_NOT_FOUND,
-            "Method '%s' not found", string_to_cstring(interp, $3));
+            "Method '%s' not found", method_name);
+        string_cstring_free(method_name);
+    }
     restart ADDRESS(resume);
 }
 

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c        (original)
+++ trunk/src/packfile.c        Fri Apr 20 21:54:51 2007
@@ -2147,7 +2147,7 @@
                 filename = string_to_cstring(interp, PF_CONST(debug->code,
                            debug->mappings[i]->u.filename)->u.string);
                 PIO_printf(interp, "        FILENAME => %s\n", filename);
-                free(filename);
+                string_cstring_free(filename);
                 break;
             case PF_DEBUGMAPPINGTYPE_SOURCESEG:
                 PIO_printf(interp, "        MAPPINGTYPE => SOURCESEG,\n");

Modified: trunk/src/pmc/delegate.pmc
==============================================================================
--- trunk/src/pmc/delegate.pmc  (original)
+++ trunk/src/pmc/delegate.pmc  Fri Apr 20 21:54:51 2007
@@ -64,21 +64,23 @@
 find_or_die(Interp *interp, PMC *pmc, STRING *meth) {
     PMC *returnPMC = find_meth(interp, pmc, meth);
     if (PMC_IS_NULL(returnPMC)) {
-        PMC *_class = pmc;
+        PMC  *_class    = pmc;
+        char *meth_name = string_to_cstring(interp, meth);
         if (PObj_is_object_TEST(pmc)) {
+            char *obj_name  = string_to_cstring(interp, PMC_str_val(
+                        get_attrib_num((SLOTTYPE *)PMC_data(_class),
+                            PCD_CLASS_NAME)));
             _class = GET_CLASS(PMC_data(pmc), pmc);
             real_exception(interp, NULL, E_LookupError,
-                "Can't find method '%s' for object '%s'",
-                string_to_cstring(interp, meth),
-                string_to_cstring(interp, PMC_str_val(
-                        get_attrib_num((SLOTTYPE *)PMC_data(_class),
-                            PCD_CLASS_NAME))));
+                "Can't find method '%s' for object '%s'", meth_name, obj_name);
+            string_cstring_free(obj_name);
         }
         else {
             real_exception(interp, NULL, E_LookupError,
                 "Can't find method '%s' - erroneous PMC",
                 string_to_cstring(interp, meth));
         }
+        string_cstring_free(meth_name);
     }
     return returnPMC;
 }

Modified: trunk/src/pmc/env.pmc
==============================================================================
--- trunk/src/pmc/env.pmc       (original)
+++ trunk/src/pmc/env.pmc       Fri Apr 20 21:54:51 2007
@@ -218,15 +218,16 @@
         char *keyname = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
         char *env_val = string_to_cstring(INTERP, value);
-        if (keyname && env_val) {
+
+        if (keyname && env_val)
             Parrot_setenv(keyname, env_val);
-        }
-        if (keyname) {
+
+        if (keyname)
             string_cstring_free(keyname);
-        }
-        if (env_val) {
+
+        if (env_val)
             string_cstring_free(env_val);
-        }
+
     }
 
 /*
@@ -240,19 +241,19 @@
 */
 
     void set_pmc_keyed(PMC* key, PMC* value) {
-        char *keyname = string_to_cstring(INTERP,
+        char *keyname     = string_to_cstring(INTERP,
             VTABLE_get_string(INTERP, key));
         STRING *str_value = VTABLE_get_string(INTERP, value);
-        char *env_val = string_to_cstring(INTERP, str_value);
-        if (keyname && env_val) {
+        char   *env_val   = string_to_cstring(INTERP, str_value);
+
+        if (keyname && env_val)
             Parrot_setenv(keyname, env_val);
-        }
-        if (keyname) {
+
+        if (keyname)
             string_cstring_free(keyname);
-        }
-        if (env_val) {
+
+        if (env_val)
             string_cstring_free(env_val);
-        }
     }
 
 /*

Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Fri Apr 20 21:54:51 2007
@@ -506,10 +506,13 @@
         if (ns == PMCNULL)
             return;
 
-        if (!VTABLE_isa(INTERP, ns, s_ns))
+        if (!VTABLE_isa(INTERP, ns, s_ns)) {
+            char *item_name = string_to_cstring(INTERP, name);
             real_exception(INTERP, NULL, E_TypeError,
                 "Invalid type %d for '%s' in del_namespace()",
-                ns->vtable->base_type, string_to_cstring(INTERP, name));
+                ns->vtable->base_type, item_name);
+            string_cstring_free(item_name);
+        }
 
         parrot_hash_delete(INTERP, hash, name);
     }
@@ -536,10 +539,13 @@
         if (sub == PMCNULL)
             return;
 
-        if (!VTABLE_isa(INTERP, sub, s_sub))
+        if (!VTABLE_isa(INTERP, sub, s_sub)) {
+            char *item_name = string_to_cstring(INTERP, name);
             real_exception(INTERP, NULL, E_TypeError,
                 "Invalid type %d for '%s' in del_sub()",
-                sub->vtable->base_type, string_to_cstring(INTERP, name));
+                sub->vtable->base_type, item_name);
+            string_cstring_free(item_name);
+        }
 
         parrot_hash_delete(INTERP, hash, name);
     }

Modified: trunk/src/pmc/os.pmc
==============================================================================
--- trunk/src/pmc/os.pmc        (original)
+++ trunk/src/pmc/os.pmc        Fri Apr 20 21:54:51 2007
@@ -501,6 +501,10 @@
         int ret;
 
         ret = rename(coldpath, cnewpath);
+
+        string_cstring_free(coldpath);
+        string_cstring_free(cnewpath);
+
         if (ret < 0)
         {
             char *errmsg = strerror(errno) ;

Modified: trunk/src/pmc/parrotio.pmc
==============================================================================
--- trunk/src/pmc/parrotio.pmc  (original)
+++ trunk/src/pmc/parrotio.pmc  Fri Apr 20 21:54:51 2007
@@ -64,11 +64,16 @@
         const char *c_file, *c_mode, *c_layer;
         PMC *pio;
 
-        c_file = string_to_cstring(INTERP, file);
-        c_mode = string_to_cstring(INTERP, mode);
+        c_file  = string_to_cstring(INTERP, file);
+        c_mode  = string_to_cstring(INTERP, mode);
         c_layer = string_to_cstring(INTERP, layer);
-        l = PIO_get_layer(INTERP, c_layer);
-        pio = PIO_open(INTERP, l, c_file, c_mode);
+        l       = PIO_get_layer(INTERP, c_layer);
+        pio     = PIO_open(INTERP, l, c_file, c_mode);
+
+        string_cstring_free(c_file);
+        string_cstring_free(c_mode);
+        string_cstring_free(c_layer);
+
         if (!pio || !PMC_struct_val(pio))
             return pmc_new(INTERP, enum_class_Undef);
         if (l) {

Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c     (original)
+++ trunk/src/sub.c     Fri Apr 20 21:54:51 2007
@@ -391,12 +391,18 @@
 
     Parrot_block_DOD(interp);
     if (Parrot_Context_info(interp, ctx, &info)) {
-        res = Parrot_sprintf_c(interp,
+        char *file = (char *)info.file;
+        res        = Parrot_sprintf_c(interp,
             "%s '%Ss' pc %d (%s:%d)", msg,
-            info.fullname, info.pc, info.file, info.line);
+            info.fullname, info.pc, file, info.line);
+
+        /* free the non-constant string, but not the constant one */
+        if (strncmp( "(unknown file)", file, 14 ) < 0 )
+            string_cstring_free(file);
     }
     else
         res = NULL;
+
     Parrot_unblock_DOD(interp);
     return res;
 }

Modified: trunk/src/utils.c
==============================================================================
--- trunk/src/utils.c   (original)
+++ trunk/src/utils.c   Fri Apr 20 21:54:51 2007
@@ -512,6 +512,8 @@
 
 Currently unused.
 
+Note that you need to free this array with C<Parrot_destroy_cpa()>.
+
 =cut
 
 */

Reply via email to