[grisbi-devel] [PATCH 5/6] Fix memory leaks in gsb_data_payee_get_name_and_report_list () and gsb_form_widget_create ()

pbiava pierre.biava at nerim.net
Mon Jun 17 21:34:14 CEST 2013


---
 src/gsb_data_payee.c  | 34 ++++++++++++++++++++++------------
 src/gsb_data_payee.h  |  1 +
 src/gsb_form_widget.c |  7 +++++--
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/src/gsb_data_payee.c b/src/gsb_data_payee.c
index 534b804..3b16cd7 100644
--- a/src/gsb_data_payee.c
+++ b/src/gsb_data_payee.c
@@ -530,32 +530,42 @@ GSList *gsb_data_payee_get_name_and_report_list ( void )
 
 	if ( gsb_data_report_get_append_in_payee (report_number))
 	{
+        gchar *tmp_str;
+
+        tmp_str = my_strdup ( gsb_data_report_get_report_name ( report_number ) );
 	    if ( tmp_list )
-		tmp_list = g_slist_append ( tmp_list,
-					    g_strconcat ( "\t",
-							  my_strdup (gsb_data_report_get_report_name(report_number)),
-							  NULL ));
+            tmp_list = g_slist_append ( tmp_list, g_strconcat ( "\t", tmp_str, NULL ) );
 	    else
 	    {
-		tmp_list = g_slist_append ( tmp_list,
-					    g_strdup(_("Report")));
-		tmp_list = g_slist_append ( tmp_list,
-					    g_strconcat ( "\t",
-							  my_strdup (gsb_data_report_get_report_name(report_number)),
-							  NULL ));
+            tmp_list = g_slist_append ( tmp_list, g_strdup ( _("Report") ) );
+            tmp_list = g_slist_append ( tmp_list, g_strconcat ( "\t", tmp_str, NULL ) );
 	    }
+        g_free ( tmp_str );
 	}
 	pointer = pointer -> next;
     }
 
     if (tmp_list)
-	return_list = g_slist_append ( return_list,
-				       tmp_list );
+        return_list = g_slist_append ( return_list, tmp_list );
 
     return return_list;
 }
 
 
+void gsb_data_payee_free_name_and_report_list ( GSList *liste )
+{
+    if ( g_slist_length ( liste ) == 2 )
+    {
+        GSList *tmp_list;
+
+        tmp_list = g_slist_nth_data ( liste, 1 );
+        g_slist_foreach ( tmp_list, (GFunc) g_free, NULL );
+        g_slist_free ( tmp_list );
+    }
+    g_slist_free ( liste->data );
+    g_slist_free ( liste );
+}
+
 /**
  * return the description of the payee
  *
diff --git a/src/gsb_data_payee.h b/src/gsb_data_payee.h
index 677479e..4958b38 100644
--- a/src/gsb_data_payee.h
+++ b/src/gsb_data_payee.h
@@ -10,6 +10,7 @@
 
 /* START_DECLARATION */
 void gsb_data_payee_add_transaction_to_payee ( gint transaction_number );
+void gsb_data_payee_free_name_and_report_list ( GSList *liste );
 gsb_real gsb_data_payee_get_balance ( gint no_payee );
 const gchar *gsb_data_payee_get_description ( gint no_payee );
 gpointer gsb_data_payee_get_empty_payee ( void );
diff --git a/src/gsb_form_widget.c b/src/gsb_form_widget.c
index d506060..bae8043 100644
--- a/src/gsb_form_widget.c
+++ b/src/gsb_form_widget.c
@@ -200,6 +200,7 @@ GtkWidget *gsb_form_widget_create ( gint element_number,
                         gint account_number )
 {
     GtkWidget *widget;
+    GSList *tmp_list;
 
     if (!element_number)
 	return NULL;
@@ -246,8 +247,10 @@ GtkWidget *gsb_form_widget_create ( gint element_number,
 	    break;
 
 	case TRANSACTION_FORM_PARTY:
-	    widget = gtk_combofix_new (
-                        gsb_data_payee_get_name_and_report_list ( ) );
+        tmp_list = gsb_data_payee_get_name_and_report_list ( );
+	    widget = gtk_combofix_new ( tmp_list );
+        gsb_data_payee_free_name_and_report_list ( tmp_list );
+
 	    gtk_combofix_set_force_text ( GTK_COMBOFIX (widget),
 					  etat.combofix_force_payee );
 	    gtk_combofix_set_max_items ( GTK_COMBOFIX (widget),
-- 
1.8.1.5



More information about the devel mailing list