r20739 - gnucash/trunk/src/report/report-gnome - Fix memory leaks found with valgrind

J. Alex Aycinena alex.aycinena at code.gnucash.org
Wed Jun 8 12:46:32 EDT 2011


Author: alex.aycinena
Date: 2011-06-08 12:46:32 -0400 (Wed, 08 Jun 2011)
New Revision: 20739
Trac: http://svn.gnucash.org/trac/changeset/20739

Modified:
   gnucash/trunk/src/report/report-gnome/dialog-column-view.c
   gnucash/trunk/src/report/report-gnome/dialog-style-sheet.c
   gnucash/trunk/src/report/report-gnome/window-report.c
Log:
Fix memory leaks found with valgrind

Modified: gnucash/trunk/src/report/report-gnome/dialog-column-view.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-column-view.c	2011-06-08 01:42:12 UTC (rev 20738)
+++ gnucash/trunk/src/report/report-gnome/dialog-column-view.c	2011-06-08 16:46:32 UTC (rev 20739)
@@ -150,10 +150,16 @@
     {
         for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
         {
+            char * str;
+
             if (scm_is_equal (SCM_CAR(names), selection))
                 row = i;
-            name = _(scm_to_locale_string(scm_call_2(template_menu_name, SCM_CAR(names),
-                                          SCM_BOOL_F)));
+            scm_dynwind_begin (0); 
+            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
+                                          SCM_BOOL_F));
+            name = _(g_strdup (str));
+            scm_dynwind_free (str); 
+            scm_dynwind_end (); 
             gtk_list_store_append(store, &iter);
             gtk_list_store_set(store, &iter,
                                AVAILABLE_COL_NAME, name,
@@ -192,12 +198,18 @@
     {
         for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
         {
+            char * str;
+
             if (scm_is_equal (SCM_CAR(contents), selection))
                 row = i;
 
             id = scm_num2int(SCM_CAAR(contents), SCM_ARG1, G_STRFUNC);
             this_report = gnc_report_find(id);
-            name = _(scm_to_locale_string(scm_call_1(report_menu_name, this_report)));
+            scm_dynwind_begin (0); 
+            str = scm_to_locale_string (scm_call_1(report_menu_name, this_report));
+            name = _(g_strdup (str));
+            scm_dynwind_free (str); 
+            scm_dynwind_end (); 
 
             gtk_list_store_append(store, &iter);
             gtk_list_store_set

Modified: gnucash/trunk/src/report/report-gnome/dialog-style-sheet.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-style-sheet.c	2011-06-08 01:42:12 UTC (rev 20738)
+++ gnucash/trunk/src/report/report-gnome/dialog-style-sheet.c	2011-06-08 16:46:32 UTC (rev 20739)
@@ -199,8 +199,15 @@
     /* put in the list of style sheet type names */
     for (; !scm_is_null(templates); templates = SCM_CDR(templates))
     {
+        char * str;
+        const char* orig_name;
+
         SCM t = SCM_CAR(templates);
-        const char* orig_name = scm_to_locale_string(scm_call_1(t_name, t));
+        scm_dynwind_begin (0); 
+        str = scm_to_locale_string (scm_call_1(t_name, t));
+        orig_name = g_strdup (str);
+        scm_dynwind_free (str); 
+        scm_dynwind_end (); 
 
         /* Store the untranslated names for lookup later */
         template_names = g_list_prepend (template_names, (gpointer)orig_name);
@@ -251,12 +258,17 @@
 {
     SCM get_name, scm_name;
     const gchar *c_name;
+    char * str;
     GtkTreeSelection *selection;
     GtkTreeIter iter;
 
     get_name = scm_c_eval_string("gnc:html-style-sheet-name");
     scm_name = scm_call_1(get_name, sheet_info);
-    c_name = scm_to_locale_string(scm_name);
+    scm_dynwind_begin (0); 
+    str = scm_to_locale_string (scm_name);
+    c_name = g_strdup (str);
+    scm_dynwind_free (str); 
+    scm_dynwind_end (); 
     if (!c_name)
         return;
 

Modified: gnucash/trunk/src/report/report-gnome/window-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/window-report.c	2011-06-08 01:42:12 UTC (rev 20738)
+++ gnucash/trunk/src/report/report-gnome/window-report.c	2011-06-08 16:46:32 UTC (rev 20739)
@@ -159,13 +159,23 @@
             {
                 ptr = scm_call_1(get_template_name, ptr);
                 if (scm_is_string(ptr))
-                    title = scm_to_locale_string(ptr);
+                {
+                    char * str;
+
+                    scm_dynwind_begin (0); 
+                    str = scm_to_locale_string (ptr);
+                    title = g_strdup (str);
+                    scm_dynwind_free (str); 
+                    scm_dynwind_end (); 
+                }
             }
         }
 
         /* Don't forget to translate the window title */
         prm->win  = gnc_options_dialog_new((gchar*) (title && *title ? _(title) : ""));
 
+        g_free ((gpointer *) title);
+
         scm_gc_protect_object(prm->scm_options);
         scm_gc_protect_object(prm->cur_report);
 



More information about the gnucash-changes mailing list