r19988 - gnucash/trunk/src - Fix earlier checkins to ensure that strings returned from routines or whose addresses are kept have been allocated from g_malloc(.

Phil Longstaff plongstaff at code.gnucash.org
Tue Dec 28 22:03:10 EST 2010


Author: plongstaff
Date: 2010-12-28 22:03:10 -0500 (Tue, 28 Dec 2010)
New Revision: 19988
Trac: http://svn.gnucash.org/trac/changeset/19988

Modified:
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c
Log:
Fix earlier checkins to ensure that strings returned from routines or whose addresses are kept have been allocated from g_malloc(.


Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2010-12-29 01:43:28 UTC (rev 19987)
+++ gnucash/trunk/src/app-utils/guile-util.c	2010-12-29 03:03:10 UTC (rev 19988)
@@ -150,7 +150,7 @@
  *                                                                  *
  * Args: func - the guile function to call                          *
  *       arg  - the single function argument                        *
- * Returns: malloc'ed char * or NULL                                *
+ * Returns: g_malloc'ed char * or NULL                              *
 \********************************************************************/
 char *
 gnc_guile_call1_to_string(SCM func, SCM arg)
@@ -162,7 +162,18 @@
         value = scm_call_1(func, arg);
 
         if (scm_is_string(value))
-            return scm_to_locale_string(value);
+        {
+            char* x;
+            gchar* s;
+
+            x = scm_to_locale_string(value);
+
+            /* scm_to_locale_string() returns a malloc'ed string.
+               Copy to a g_malloc'ed one. */
+            s = g_strdup(x);
+            free(x);
+            return s;
+        }
         else
         {
             PERR("bad value\n");
@@ -650,6 +661,8 @@
 gnc_split_scm_get_memo(SCM split_scm)
 {
     SCM result;
+    char* x;
+    gchar* s;
 
     initialize_scm_functions();
 
@@ -660,7 +673,13 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    x = scm_to_locale_string(result);
+
+    /* scm_to_locale_string() returns a malloc'ed string.
+       Copy to a g_malloc'ed one. */
+    s = g_strdup(x);
+    free(x);
+    return s;
 }
 
 
@@ -675,6 +694,8 @@
 gnc_split_scm_get_action(SCM split_scm)
 {
     SCM result;
+    char* x;
+    gchar* s;
 
     initialize_scm_functions();
 
@@ -685,7 +706,13 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    x = scm_to_locale_string(result);
+
+    /* scm_to_locale_string() returns a malloc'ed string.
+       Copy to a g_malloc'ed one. */
+    s = g_strdup(x);
+    free(x);
+    return s;
 }
 
 
@@ -1100,6 +1127,8 @@
     const gchar *string;
     SCM result;
     SCM arg;
+    char* x;
+    gchar* s;
 
     initialize_scm_functions();
 
@@ -1115,7 +1144,13 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    x = scm_to_locale_string(result);
+
+    /* scm_to_locale_string() returns a malloc'ed string.
+       Copy to a g_malloc'ed one. */
+    s = g_strdup(x);
+    free(x);
+    return s;
 }
 
 
@@ -1132,6 +1167,8 @@
     const gchar *string;
     SCM result;
     SCM arg;
+    char* x;
+    gchar* s;
 
     initialize_scm_functions();
 
@@ -1147,7 +1184,13 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    x = scm_to_locale_string(result);
+
+    /* scm_to_locale_string() returns a malloc'ed string.
+       Copy to a g_malloc'ed one. */
+    s = g_strdup(x);
+    free(x);
+    return s;
 }
 
 

Modified: gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c	2010-12-29 01:43:28 UTC (rev 19987)
+++ gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c	2010-12-29 03:03:10 UTC (rev 19988)
@@ -171,18 +171,20 @@
 
         if (scm_is_string(item))
         {
+            char* s;
+
+            s = scm_to_locale_string(item);
+
             if (i == 1)
             {
-                strings[i] = scm_to_locale_string(item);
+
+                strings[i] = g_strdup(s);
             }
             else
             {
-                gchar* s;
-
-                s = scm_to_locale_string(item);
                 strings[i] = g_strdup(gettext(s));
-                free(s);
             }
+            free(s);
         }
         else
         {
@@ -283,8 +285,8 @@
     ext_info->ae.stock_id = NULL;
     ext_info->ae.accelerator = NULL;
     ext_info->ae.callback = NULL;
-    free(name);
-    free(guid);
+    g_free(name);
+    g_free(guid);
 
     tmp = g_strdup_printf("%s/%s", ext_info->path, ext_info->ae.label);
     ext_info->sort_key = g_utf8_collate_key(tmp, -1);



More information about the gnucash-changes mailing list