gnucash maint: gchar *gnc_account_get_full_name must be freed

Christopher Lam clam at code.gnucash.org
Thu Aug 5 11:13:39 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/86bc9d93 (commit)
	from  https://github.com/Gnucash/gnucash/commit/de1ad936 (commit)



commit 86bc9d93a7be0d92f5083eced12b73eab089719c
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Aug 5 22:09:24 2021 +0800

    gchar *gnc_account_get_full_name must be freed
    
    The gnc-account-sel.c one was causing a runaway leak -- leaked
    full_name for every account (except the matched account) in the
    GNCAccountSel. Interestingly the original commit[*] suggests the name
    should have been freed correctly however the braces prohibited it.
    
    [*] e5b0bdbe109abad193f8419b485ce34d45cf5cc5

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index cba3b531e..e7ecf2e6c 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -2163,7 +2163,7 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
     RenumberDialog *data;
     GtkBuilder *builder;
     GtkWidget *widget;
-    gchar *string;
+    gchar *string, *fullname;
 
     /* This is a safety check; the menu item calling this dialog
      * should be disabled if the account has no children.
@@ -2182,12 +2182,14 @@ gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
                g_object_unref);
 
     widget = GTK_WIDGET(gtk_builder_get_object (builder, "header_label"));
+    fullname = gnc_account_get_full_name (account);
     string = g_strdup_printf(_( "Renumber the immediate sub-accounts of %s? "
                                 "This will replace the account code field of "
                                 "each child account with a newly generated code."),
-                             gnc_account_get_full_name(account));
+                             fullname);
     gtk_label_set_text(GTK_LABEL(widget), string);
     g_free(string);
+    g_free (fullname);
 
     data->prefix = GTK_WIDGET(gtk_builder_get_object (builder, "prefix_entry"));
     data->interval = GTK_WIDGET(gtk_builder_get_object (builder, "interval_spin"));
@@ -2256,7 +2258,7 @@ gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account)
     GtkWidget *color_box, *placeholder_box, *hidden_box;
     GtkWidget *placeholder_button, *hidden_button;
 
-    gchar *string;
+    gchar *string, *fullname;
     const char *color_string;
     gchar *old_color_string = NULL;
     GdkRGBA color;
@@ -2287,9 +2289,10 @@ gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account)
     g_signal_connect (G_OBJECT(color_button_default), "clicked",
                       G_CALLBACK(default_color_button_cb), (gpointer)color_button);
 
+    fullname = gnc_account_get_full_name (account);
     string = g_strdup_printf (_( "Set the account color for account '%s' "
                                  "including all sub-accounts to the selected color"),
-                              gnc_account_get_full_name (account));
+                              fullname);
     gtk_label_set_text (GTK_LABEL(label), string);
     g_free (string);
 
@@ -2316,7 +2319,7 @@ gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account)
 
     string = g_strdup_printf (_( "Set the account placeholder value for account '%s' "
                                  "including all sub-accounts"),
-                              gnc_account_get_full_name (account));
+                              fullname);
     gtk_label_set_text (GTK_LABEL(label), string);
     g_free (string);
 
@@ -2330,9 +2333,10 @@ gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account)
 
     string = g_strdup_printf (_( "Set the account hidden value for account '%s' "
                                  "including all sub-accounts"),
-                              gnc_account_get_full_name (account));
+                              fullname);
     gtk_label_set_text (GTK_LABEL(label), string);
     g_free (string);
+    g_free (fullname);
 
     /* default to cancel */
     gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
diff --git a/gnucash/gnome-utils/gnc-account-sel.c b/gnucash/gnome-utils/gnc-account-sel.c
index 9174a663c..25126c4a1 100644
--- a/gnucash/gnome-utils/gnc-account-sel.c
+++ b/gnucash/gnome-utils/gnc-account-sel.c
@@ -233,10 +233,8 @@ gas_populate_list (GNCAccountSel *gas)
                             ACCT_COL_PTR,  acc,
                             -1);
         if (g_utf8_collate (name, currentSel) == 0)
-        {
             active = i;
-            g_free (name);
-        }
+        g_free (name);
     }
 
     /* If the account which was in the text box before still exists, then
diff --git a/gnucash/import-export/import-account-matcher.c b/gnucash/import-export/import-account-matcher.c
index 849e935c5..55cc3d5a7 100644
--- a/gnucash/import-export/import-account-matcher.c
+++ b/gnucash/import-export/import-account-matcher.c
@@ -148,11 +148,14 @@ static gpointer test_acct_online_id_match(Account *acct, gpointer data)
              */
             else if (partial_len == acct_len)
             {
+                gchar *name1, *name2;
                 ++match->count;
+                name1 = gnc_account_get_full_name (match->partial_match);
+                name2 = gnc_account_get_full_name (acct);
                 PERR("Accounts %s and %s have the same online-id %s",
-                     gnc_account_get_full_name(match->partial_match),
-                     gnc_account_get_full_name(acct),
-                     partial_online_id);
+                     name1, name2, partial_online_id);
+                g_free (name1);
+                g_free (name2);
             }
         }
     }
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index 0c31c5a52..9e2f66ddd 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -735,6 +735,7 @@ gnc_gen_trans_assign_transfer_account (GtkTreeView *treeview,
                 old_acc  = gnc_import_TransInfo_get_destacc (trans_info);
                 if (*first)
                 {
+                    gchar *acc_full_name = gnc_account_get_full_name (*new_acc);
                     ok_pressed = FALSE;
                     *new_acc = gnc_import_select_account (info->main_widget,
                         NULL,
@@ -746,8 +747,9 @@ gnc_gen_trans_assign_transfer_account (GtkTreeView *treeview,
                         old_acc,
                         &ok_pressed);
                     *first = FALSE;
-                    DEBUG("account selected = %s",
-                            gnc_account_get_full_name (*new_acc));
+                    acc_full_name = gnc_account_get_full_name (*new_acc);
+                    DEBUG("account selected = %s", acc_full_name);
+                    g_free (acc_full_name);
                 }
                 if (ok_pressed)
                 {
@@ -805,19 +807,22 @@ gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *menuitem,
         {
             gchar *path_str = gtk_tree_path_to_string (l->data);
             GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, l->data);
+            gchar *fullname;
             DEBUG("passing first = %s", first ? "true" : "false");
             DEBUG("passing is_selection = %s", is_selection ? "true" : "false");
             DEBUG("passing path = %s", path_str);
             g_free (path_str);
             refs = g_list_prepend (refs, ref);
-            DEBUG("passing account value = %s",
-                        gnc_account_get_full_name (assigned_account));
+            fullname = gnc_account_get_full_name (assigned_account);
+            DEBUG("passing account value = %s", fullname);
+            g_free (fullname);
             gnc_gen_trans_assign_transfer_account (treeview,
                                                    &first, is_selection, l->data,
                                                    &assigned_account, info);
-            DEBUG("returned value of account = %s",
-                        gnc_account_get_full_name (assigned_account));
+            fullname = gnc_account_get_full_name (assigned_account);
+            DEBUG("returned value of account = %s", fullname);
             DEBUG("returned value of first = %s", first ? "true" : "false");
+            g_free (fullname);
             if (assigned_account == NULL)
                 break;
 
@@ -848,6 +853,7 @@ gnc_gen_trans_row_activated_cb (GtkTreeView *treeview,
 {
     Account *assigned_account;
     gboolean first, is_selection;
+    gchar *namestr;
 
     ENTER("");
     assigned_account = NULL;
@@ -859,7 +865,9 @@ gnc_gen_trans_row_activated_cb (GtkTreeView *treeview,
 
     gtk_tree_selection_select_path (gtk_tree_view_get_selection (treeview), path);
 
-    DEBUG("account returned = %s", gnc_account_get_full_name (assigned_account));
+    namestr = gnc_account_get_full_name (assigned_account);
+    DEBUG("account returned = %s", namestr);
+    g_free (namestr);
     LEAVE("");
 }
 



Summary of changes:
 gnucash/gnome-utils/dialog-account.c           | 16 ++++++++++------
 gnucash/gnome-utils/gnc-account-sel.c          |  4 +---
 gnucash/import-export/import-account-matcher.c |  9 ++++++---
 gnucash/import-export/import-main-matcher.c    | 22 +++++++++++++++-------
 4 files changed, 32 insertions(+), 19 deletions(-)



More information about the gnucash-changes mailing list