[grisbi-test] [PATCH 09/10] fix memeory leaks in gsb_form_widget_create () for categories
pbiava
pierre.biava at nerim.net
Dim 21 Juil 19:52:32 CEST 2013
---
src/gsb_data_category.c | 40 ++++++++++++++++++++++++++++++++--------
src/gsb_data_category.h | 1 +
src/gsb_form_widget.c | 5 +++--
3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/gsb_data_category.c b/src/gsb_data_category.c
index 2736c59..7c31aa0 100644
--- a/src/gsb_data_category.c
+++ b/src/gsb_data_category.c
@@ -1020,8 +1020,7 @@ GSList *gsb_data_category_get_name_list ( gboolean set_debit,
{
if ( set_debit )
{
- debit_list = g_slist_append ( debit_list,
- category -> category_name);
+ debit_list = g_slist_append ( debit_list, g_strdup ( category -> category_name ) );
debit_list = gsb_data_category_append_sub_category_to_list ( debit_list,
category -> sub_category_list);
}
@@ -1030,8 +1029,7 @@ GSList *gsb_data_category_get_name_list ( gboolean set_debit,
{
if ( set_credit )
{
- credit_list = g_slist_append ( credit_list,
- category -> category_name);
+ credit_list = g_slist_append ( credit_list, g_strdup ( category -> category_name ) );
credit_list = gsb_data_category_append_sub_category_to_list ( credit_list,
category -> sub_category_list);
}
@@ -1055,10 +1053,8 @@ GSList *gsb_data_category_get_name_list ( gboolean set_debit,
GSList *special_list = NULL;
if (set_split)
- special_list = g_slist_append ( special_list,
- _("Split of transaction"));
- special_list = g_slist_append ( special_list,
- _("Transfer"));
+ special_list = g_slist_append ( special_list, g_strdup ( _("Split of transaction") ) );
+ special_list = g_slist_append ( special_list, g_strdup ( _("Transfer") ) );
/* append the accounts name with a tab at the beginning */
@@ -1083,6 +1079,34 @@ GSList *gsb_data_category_get_name_list ( gboolean set_debit,
}
+/**
+ * free the memory used by gsb_data_category_get_name_list
+ *
+ * \param liste
+ *
+ * \return
+ */
+void gsb_data_categorie_free_name_list ( GSList *liste )
+{
+ gint nbre_list;
+ gint i;
+
+ nbre_list = g_slist_length ( liste );
+
+ for ( i = 0; i < nbre_list -1; i++ )
+ {
+ GSList *tmp_list;
+
+ tmp_list = liste->data;
+ liste = liste->next;
+ g_slist_foreach ( tmp_list, (GFunc) g_free, NULL );
+ g_slist_free ( tmp_list );
+ }
+
+ g_slist_free ( liste );
+}
+
+
/**
* append the sub-categories name with a tab at the beginning
diff --git a/src/gsb_data_category.h b/src/gsb_data_category.h
index 3d754f0..43a2ffd 100644
--- a/src/gsb_data_category.h
+++ b/src/gsb_data_category.h
@@ -21,6 +21,7 @@ void gsb_data_category_add_transaction_to_category ( gint transaction_number,
gboolean gsb_data_category_fill_transaction_by_string ( gint transaction_number,
const gchar *string,
gboolean is_transaction );
+void gsb_data_categorie_free_name_list ( GSList *liste );
gsb_real gsb_data_category_get_balance ( gint no_category );
GSList *gsb_data_category_get_categories_list ( void );
gsb_real gsb_data_category_get_direct_balance ( gint no_category );
diff --git a/src/gsb_form_widget.c b/src/gsb_form_widget.c
index bae8043..d30c7d6 100644
--- a/src/gsb_form_widget.c
+++ b/src/gsb_form_widget.c
@@ -264,8 +264,9 @@ GtkWidget *gsb_form_widget_create ( gint element_number,
break;
case TRANSACTION_FORM_CATEGORY:
- widget = gtk_combofix_new (
- gsb_data_category_get_name_list ( TRUE, TRUE, TRUE, TRUE ) );
+ tmp_list = gsb_data_category_get_name_list ( TRUE, TRUE, TRUE, TRUE );
+ widget = gtk_combofix_new ( tmp_list );
+ gsb_data_categorie_free_name_list ( tmp_list );
gtk_combofix_set_force_text ( GTK_COMBOFIX (widget),
etat.combofix_force_category );
gtk_combofix_set_max_items ( GTK_COMBOFIX (widget),
--
1.8.1.5
Plus d'informations sur la liste de diffusion test