From fb42065213b58dc80d85f5a2b52f092464619d73 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 29 Aug 2020 19:29:03 +0800 Subject: [PATCH] g_free strings allocated with gnc_prefs_get_string gnc_prefs_get_string will return a newly-allocated string. after use, they must be g_freed. --- gnucash/gnome-utils/dialog-file-access.c | 1 + gnucash/gnome-utils/gnc-plugin-file-history.c | 12 ++++++++++-- gnucash/gnome/dialog-print-check.c | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/dialog-file-access.c b/gnucash/gnome-utils/dialog-file-access.c index 363ae6fc55..18b521090d 100644 --- a/gnucash/gnome-utils/dialog-file-access.c +++ b/gnucash/gnome-utils/dialog-file-access.c @@ -343,6 +343,7 @@ gnc_ui_file_access (GtkWindow *parent, int type) faw->starting_dir = g_path_get_dirname( filepath ); g_free ( filepath ); } + g_free (last); } if (!faw->starting_dir) faw->starting_dir = gnc_get_default_directory(settings_section); diff --git a/gnucash/gnome-utils/gnc-plugin-file-history.c b/gnucash/gnome-utils/gnc-plugin-file-history.c index da69b5d88f..bf3e3600b4 100644 --- a/gnucash/gnome-utils/gnc-plugin-file-history.c +++ b/gnucash/gnome-utils/gnc-plugin-file-history.c @@ -256,6 +256,7 @@ gnc_history_remove_file (const char *oldfile) } j++; } + g_free (filename); } g_free(from); } @@ -283,12 +284,18 @@ gboolean gnc_history_test_for_file (const char *oldfile) filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from); g_free(from); - if (filename && (g_utf8_collate(oldfile, filename) == 0)) + if (!filename) + continue; + + if (g_utf8_collate(oldfile, filename) == 0) { found = TRUE; + g_free (filename); break; } + g_free (filename); } + return found; } @@ -488,7 +495,7 @@ gnc_plugin_history_list_changed (gpointer prefs, gpointer user_data) { GncMainWindow *window; - const gchar *filename; + gchar *filename; gint index; ENTER(""); @@ -509,6 +516,7 @@ gnc_plugin_history_list_changed (gpointer prefs, filename = gnc_prefs_get_string (GNC_PREFS_GROUP_HISTORY, pref); gnc_history_update_action (window, index, filename); + g_free (filename); gnc_main_window_actions_updated (window); LEAVE(""); diff --git a/gnucash/gnome/dialog-print-check.c b/gnucash/gnome/dialog-print-check.c index 6aefd7e465..21a57cd289 100644 --- a/gnucash/gnome/dialog-print-check.c +++ b/gnucash/gnome/dialog-print-check.c @@ -609,8 +609,11 @@ gnc_ui_print_restore_dialog(PrintCheckDialog *pcd) if (guid == NULL) gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox), 0); else if (strcmp(guid, "custom") == 0) + { gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox), pcd->format_max - 1); + g_free (guid); + } else { model = gtk_combo_box_get_model(GTK_COMBO_BOX(pcd->format_combobox)); @@ -622,7 +625,9 @@ gnc_ui_print_restore_dialog(PrintCheckDialog *pcd) { gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox), 0); } + g_free (guid); } + active = gnc_prefs_get_int(GNC_PREFS_GROUP, GNC_PREF_CHECK_POSITION); /* If the check format used last time no longer exists, then the saved check