Fix memory leaks after usage of gtk_tree_model_get().

String results are always newly allocated and should be freed.
Similarly, GObjects should be unreffed, but I have not found such a
case.

BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17036 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2008-03-20 23:14:34 +00:00
parent 440587a30c
commit 1dd7ec7480
8 changed files with 26 additions and 10 deletions

View File

@ -43,8 +43,9 @@ gnc_cbe_set_by_string(GtkComboBoxEntry *cbe,
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
const gchar *tree_string; gchar *tree_string;
gint column, index, id; gint column, index, id;
gboolean match;
model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe)); model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe));
if (!gtk_tree_model_get_iter_first(model, &iter)) { if (!gtk_tree_model_get_iter_first(model, &iter)) {
@ -56,7 +57,9 @@ gnc_cbe_set_by_string(GtkComboBoxEntry *cbe,
column = gtk_combo_box_entry_get_text_column(cbe); column = gtk_combo_box_entry_get_text_column(cbe);
do { do {
gtk_tree_model_get(model, &iter, column, &tree_string, -1); gtk_tree_model_get(model, &iter, column, &tree_string, -1);
if (g_utf8_collate(text, tree_string) != 0) match = g_utf8_collate(text, tree_string) == 0;
g_free(tree_string);
if (!match)
continue; continue;
/* Found a matching string */ /* Found a matching string */
@ -120,6 +123,7 @@ gnc_cbe_match_selected_cb (GtkEntryCompletion *completion,
column = gtk_combo_box_entry_get_text_column(cbe); column = gtk_combo_box_entry_get_text_column(cbe);
gtk_tree_model_get(comp_model, comp_iter, column, &text, -1); gtk_tree_model_get(comp_model, comp_iter, column, &text, -1);
gnc_cbe_set_by_string(cbe, text); gnc_cbe_set_by_string(cbe, text);
g_free(text);
return FALSE; return FALSE;
} }

View File

@ -1113,6 +1113,7 @@ gxi_default_enc_combo_changed_cb (GtkComboBox *combo, GncXmlImportData *data)
gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter, gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
0, &enc_string, -1); 0, &enc_string, -1);
curr_enc = g_quark_from_string (enc_string); curr_enc = g_quark_from_string (enc_string);
g_free (enc_string);
if (data->default_encoding == curr_enc) if (data->default_encoding == curr_enc)
return; return;

View File

@ -270,7 +270,7 @@ sort_by_string (GtkTreeModel *f_model,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter1, iter2; GtkTreeIter iter1, iter2;
const Account *account1, *account2; const Account *account1, *account2;
const gchar *str1, *str2; gchar *str1, *str2;
gint column = GPOINTER_TO_INT(user_data); gint column = GPOINTER_TO_INT(user_data);
gint result; gint result;
@ -281,6 +281,8 @@ sort_by_string (GtkTreeModel *f_model,
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter2, column, &str2, -1); gtk_tree_model_get(GTK_TREE_MODEL(model), &iter2, column, &str2, -1);
result = safe_utf8_collate(str1, str2); result = safe_utf8_collate(str1, str2);
g_free(str1);
g_free(str2);
if (result != 0) if (result != 0)
return result; return result;
return xaccAccountOrder(account1, account2); return xaccAccountOrder(account1, account2);

View File

@ -277,7 +277,7 @@ sort_by_commodity_string (GtkTreeModel *f_model,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter_a, iter_b; GtkTreeIter iter_a, iter_b;
gnc_commodity *comm_a, *comm_b; gnc_commodity *comm_a, *comm_b;
const gchar *str1, *str2; gchar *str1, *str2;
gint column = GPOINTER_TO_INT(user_data); gint column = GPOINTER_TO_INT(user_data);
gint result; gint result;
@ -290,6 +290,8 @@ sort_by_commodity_string (GtkTreeModel *f_model,
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_b, column, &str2, -1); gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_b, column, &str2, -1);
result = safe_utf8_collate(str1, str2); result = safe_utf8_collate(str1, str2);
g_free(str1);
g_free(str2);
if (result != 0) if (result != 0)
return result; return result;
return default_sort(comm_a, comm_b); return default_sort(comm_a, comm_b);

View File

@ -253,6 +253,7 @@ static void ok_button_clicked(GtkWidget* widget, GncCsvPreview* preview)
for(i = 0; i < ncols; i++) for(i = 0; i < ncols; i++)
{ {
int type; /* The column type contained in this column. */ int type; /* The column type contained in this column. */
gboolean found;
gchar* contents; /* The column type string in this column. */ gchar* contents; /* The column type string in this column. */
/* Get the type string first. (store is arranged so that every two /* Get the type string first. (store is arranged so that every two
* columns is a pair of the model used for the combobox and the * columns is a pair of the model used for the combobox and the
@ -264,7 +265,9 @@ static void ok_button_clicked(GtkWidget* widget, GncCsvPreview* preview)
for(type = 0; type < GNC_CSV_NUM_COL_TYPES; type++) for(type = 0; type < GNC_CSV_NUM_COL_TYPES; type++)
{ {
/* ... we find one that matches with what's in the column. */ /* ... we find one that matches with what's in the column. */
if(!strcmp(contents, _(gnc_csv_column_type_strs[type]))) found = !strcmp(contents, _(gnc_csv_column_type_strs[type]));
g_free(contents);
if(found)
{ {
/* Set the column_types array appropriately and quit. */ /* Set the column_types array appropriately and quit. */
column_types->data[i] = type; column_types->data[i] = type;
@ -369,6 +372,7 @@ static void column_type_edited(GtkCellRenderer* renderer, gchar* path,
gtk_list_store_set(GTK_LIST_STORE(store), &iter, 2*i+1, gtk_list_store_set(GTK_LIST_STORE(store), &iter, 2*i+1,
_(gnc_csv_column_type_strs[GNC_CSV_NONE]), -1); _(gnc_csv_column_type_strs[GNC_CSV_NONE]), -1);
} }
g_free(contents);
} }
else /* If this is the column that was edited ... */ else /* If this is the column that was edited ... */
{ {

View File

@ -199,12 +199,10 @@ gnc_ui_qif_account_picker_changed_cb (GtkTreeSelection *selection,
SCM name_setter = scm_c_eval_string("qif-map-entry:set-gnc-name!"); SCM name_setter = scm_c_eval_string("qif-map-entry:set-gnc-name!");
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
gchar *name;
g_free(wind->selected_name); g_free(wind->selected_name);
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
gtk_tree_model_get(model, &iter, ACCOUNT_COL_FULLNAME, &name, -1); gtk_tree_model_get(model, &iter, ACCOUNT_COL_FULLNAME, &wind->selected_name, -1);
wind->selected_name = g_strdup(name);
scm_call_2(name_setter, wind->map_entry, scm_makfrom0str(wind->selected_name)); scm_call_2(name_setter, wind->map_entry, scm_makfrom0str(wind->selected_name));
} else { } else {
wind->selected_name = NULL; wind->selected_name = NULL;

View File

@ -124,9 +124,12 @@ _gnc_item_find_selection(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *it
{ {
FindSelectionData *to_find = (FindSelectionData*)data; FindSelectionData *to_find = (FindSelectionData*)data;
gchar *iterStr; gchar *iterStr;
gboolean found;
gtk_tree_model_get(model, iter, 0, &iterStr, -1); gtk_tree_model_get(model, iter, 0, &iterStr, -1);
if (safe_strcmp(to_find->string_to_find, iterStr) == 0) found = safe_strcmp(to_find->string_to_find, iterStr) == 0;
g_free(iterStr);
if (found)
{ {
to_find->found_path = gtk_tree_path_copy(path); to_find->found_path = gtk_tree_path_copy(path);
return TRUE; return TRUE;
@ -283,7 +286,7 @@ gnc_item_list_button_event(GtkWidget *widget, GdkEventButton *event,
gnc_item_list_signals[ACTIVATE_ITEM], gnc_item_list_signals[ACTIVATE_ITEM],
0, 0,
string); string);
g_free(string);
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;
@ -313,6 +316,7 @@ gnc_item_list_key_event (GtkWidget *widget, GdkEventKey *event, gpointer data)
gnc_item_list_signals[ACTIVATE_ITEM], gnc_item_list_signals[ACTIVATE_ITEM],
0, 0,
string); string);
g_free(string);
return TRUE; return TRUE;
case GDK_Page_Up: case GDK_Page_Up:

View File

@ -303,6 +303,7 @@ gnc_style_sheet_select_dialog_response_cb (GtkDialog *unused,
gtk_list_store_set (ss->list_store, &iter, gtk_list_store_set (ss->list_store, &iter,
COLUMN_DIALOG, ssinfo, COLUMN_DIALOG, ssinfo,
-1); -1);
g_free(name);
} }
break; break;