gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Thu May 13 10:07:31 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/ce34d0a4 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b42d2c43 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6dcf8f8e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3bd251a0 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f10b0339 (commit)



commit ce34d0a4beaf6e2a5f2b0106a00ce39c75fc1781
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 13 20:06:11 2021 +0800

    [gnc-plugin-page-register.c] plug leaks
    
    * g_free where appropriate
    * remove unnecessary g_strdup
    * don't use the string returned by g_strdelimit; it modifies the
    argument

diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index fcf312599..80772c5c5 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1414,6 +1414,7 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page)
 
     {
         gchar** filter;
+        gchar* filter_str;
         guint filtersize = 0;
         /* Set the sort order for the split register and status of save order button */
         priv->sd.save_order = FALSE;
@@ -1440,9 +1441,10 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page)
         /* Set the filter for the split register and status of save filter button */
         priv->fd.save_filter = FALSE;
 
-        filter = g_strsplit (gnc_plugin_page_register_get_filter (plugin_page), ",",
-                             -1);
+        filter_str = gnc_plugin_page_register_get_filter (plugin_page);
+        filter = g_strsplit (filter_str, ",", -1);
         filtersize = g_strv_length (filter);
+        g_free (filter_str);
 
         PINFO ("Loaded Filter Status is %s", filter[0]);
 
@@ -1974,7 +1976,7 @@ gnc_plugin_page_register_finish_pending (GncPluginPage* page)
     GncPluginPageRegister* reg_page;
     SplitRegister* reg;
     GtkWidget* dialog, *window;
-    const gchar* name;
+    gchar* name;
     gint response;
 
     if (is_scrubbing && show_abort_verify)
@@ -1999,6 +2001,7 @@ gnc_plugin_page_register_finish_pending (GncPluginPage* page)
                                      /* Translators: %s is the name
                                         of the tab page */
                                      _ ("Save changes to %s?"), name);
+    g_free (name);
     gtk_message_dialog_format_secondary_text
     (GTK_MESSAGE_DIALOG (dialog),
      "%s",
@@ -2042,7 +2045,7 @@ gnc_plugin_page_register_get_tab_name (GncPluginPage* plugin_page)
     Account* leader;
 
     g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page),
-                          _ ("unknown"));
+                          g_strdup (_("unknown")));
 
     priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
     ld = priv->ledger;
@@ -2090,7 +2093,7 @@ gnc_plugin_page_register_get_tab_color (GncPluginPage* plugin_page)
     const char* color;
 
     g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page),
-                          _ ("unknown"));
+                          g_strdup (_("unknown")));
 
     priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
     ld = priv->ledger;
@@ -2116,7 +2119,7 @@ gnc_plugin_page_register_check_for_empty_group (GKeyFile *state_file, const gcha
     g_strfreev (keys);
 }
 
-static const gchar*
+static gchar*
 gnc_plugin_page_register_get_filter_gcm (Account* leader)
 {
     GKeyFile* state_file = gnc_state_get_current();
@@ -2124,7 +2127,7 @@ gnc_plugin_page_register_get_filter_gcm (Account* leader)
     gchar* filter_text;
     gchar acct_guid[GUID_ENCODING_LENGTH + 1];
     GError* error = NULL;
-    const char* filter = NULL;
+    char* filter = NULL;
 
     // get the filter from the .gcm file
     guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -2135,11 +2138,8 @@ gnc_plugin_page_register_get_filter_gcm (Account* leader)
     if (error)
         g_clear_error (&error);
     else
-    {
-        filter_text = g_strdelimit (filter_text, ";", ',');
-        filter = g_strdup (filter_text);
-        g_free (filter_text);
-    }
+        g_strdelimit (filter_text, ";", ',');
+
     g_free (state_section);
     return filter;
 }
@@ -2150,10 +2150,10 @@ gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page)
     GncPluginPageRegisterPrivate* priv;
     GNCLedgerDisplayType ledger_type;
     Account* leader;
-    const char* filter = NULL;
+    char* filter = NULL;
 
     g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page),
-                          _ ("unknown"));
+                          g_strdup (_("unknown")));
 
     priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
 
@@ -2163,9 +2163,11 @@ gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page)
     // load from gcm file
     filter = gnc_plugin_page_register_get_filter_gcm (leader);
 
-    return filter ? g_strdup (filter) : g_strdup_printf ("%s,%s,%s,%s",
-                                                         DEFAULT_FILTER,
-                                                         "0", "0", get_filter_default_num_of_days (ledger_type));
+    if (filter)
+        return filter;
+
+    return g_strdup_printf ("%s,%s,%s,%s", DEFAULT_FILTER,
+                            "0", "0", get_filter_default_num_of_days (ledger_type));
 }
 
 static void
@@ -2190,8 +2192,7 @@ gnc_plugin_page_register_set_filter_gcm (Account* leader, const gchar* filter,
     else
     {
         filter_text = g_strdup (filter);
-        filter_text = g_strdelimit (filter_text, ",",
-                                    ';'); // make it conform to .gcm file list
+        g_strdelimit (filter_text, ",", ';'); // make it conform to .gcm file list
         g_key_file_set_string (state_file, state_section, KEY_PAGE_FILTER,
                                filter_text);
         g_free (filter_text);
@@ -2223,7 +2224,7 @@ gnc_plugin_page_register_set_filter (GncPluginPage* plugin_page,
     return;
 }
 
-static const gchar*
+static gchar*
 gnc_plugin_page_register_get_sort_order_gcm (Account* leader)
 {
     GKeyFile* state_file = gnc_state_get_current();
@@ -2231,7 +2232,7 @@ gnc_plugin_page_register_get_sort_order_gcm (Account* leader)
     gchar* sort_text;
     gchar acct_guid[GUID_ENCODING_LENGTH + 1];
     GError* error = NULL;
-    const char* sort_order = NULL;
+    char* sort_order = NULL;
 
     // get the sort_order from the .gcm file
     guid_to_string_buff (xaccAccountGetGUID (leader), acct_guid);
@@ -2255,7 +2256,7 @@ gnc_plugin_page_register_get_sort_order (GncPluginPage* plugin_page)
 {
     GncPluginPageRegisterPrivate* priv;
     Account* leader;
-    const char* sort_order = NULL;
+    char* sort_order = NULL;
 
     g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page),
                           _ ("unknown"));
@@ -2267,7 +2268,8 @@ gnc_plugin_page_register_get_sort_order (GncPluginPage* plugin_page)
     // load from gcm file
     sort_order = gnc_plugin_page_register_get_sort_order_gcm (leader);
 
-    return g_strdup (sort_order ? sort_order : DEFAULT_SORT_ORDER);
+
+    return sort_order ? sort_order : g_strdup (DEFAULT_SORT_ORDER);
 }
 
 static void

commit b42d2c43801c51b4a343a10b51bdb9ace98138c3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 13 08:04:10 2021 +0800

    [dialog-doclink-utils.c] don't use g_strdelimit return val

diff --git a/gnucash/gnome-utils/dialog-doclink-utils.c b/gnucash/gnome-utils/dialog-doclink-utils.c
index 3c00ea77f..038fbdeae 100644
--- a/gnucash/gnome-utils/dialog-doclink-utils.c
+++ b/gnucash/gnome-utils/dialog-doclink-utils.c
@@ -92,7 +92,7 @@ gnc_doclink_get_unescape_uri (const gchar *path_head, const gchar *uri, gchar *u
         g_free (file_path);
 
 #ifdef G_OS_WIN32 // make path look like a traditional windows path
-        display_str = g_strdelimit (display_str, "/", '\\');
+        g_strdelimit (display_str, "/", '\\');
 #endif
     }
     DEBUG("Return display string is '%s'", display_str);

commit 6dcf8f8e6ba96584f50a9683dc051cac34100945
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 13 08:03:50 2021 +0800

    [gnc-split-reg.c] don't use g_strdelimit return val

diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 456cd36e9..682979c24 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -428,8 +428,8 @@ gsr_move_sort_and_filter_to_state_file (GNCSplitReg *gsr, GKeyFile* state_file,
         if (kvp_filter)
         {
             gchar *temp_filter_text = g_strdup (kvp_filter);
-            temp_filter_text = g_strdelimit (temp_filter_text, ",",
-                                             ';'); // make it conform to .gcm file list
+            // make it conform to .gcm file list
+            g_strdelimit (temp_filter_text, ",", ';');
             g_key_file_set_string (state_file, state_section, KEY_PAGE_FILTER,
                                    temp_filter_text);
             g_free (temp_filter_text);

commit 3bd251a096161531e8a1d615554978a3c1700734
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 13 08:03:15 2021 +0800

    [combocell-gnome.c] simplify, more explicit assignments

diff --git a/gnucash/register/register-gnome/combocell-gnome.c b/gnucash/register/register-gnome/combocell-gnome.c
index e169416c4..7e4e243a3 100644
--- a/gnucash/register/register-gnome/combocell-gnome.c
+++ b/gnucash/register/register-gnome/combocell-gnome.c
@@ -327,13 +327,7 @@ gnc_combo_cell_destroy (BasicCell* bcell)
             box->qf = NULL;
         }
 
-        for (node = box->ignore_strings; node; node = node->next)
-        {
-            g_free (node->data);
-            node->data = NULL;
-        }
-
-        g_list_free (box->ignore_strings);
+        g_list_free_full (box->ignore_strings, g_free);
         box->ignore_strings = NULL;
 
         g_free (box);
@@ -462,7 +456,6 @@ void
 gnc_combo_cell_add_account_menu_item (ComboCell* cell, char* menustr)
 {
     PopBox* box;
-    gchar* menu_copy, *value_copy;
 
     if (cell == NULL)
         return;
@@ -478,9 +471,10 @@ gnc_combo_cell_add_account_menu_item (ComboCell* cell, char* menustr)
         gnc_item_list_append (box->item_list, menustr);
         if (cell->cell.value)
         {
-            menu_copy = g_strdelimit (g_strdup (menustr), "-:/\\.", ' ');
-            value_copy =
-                g_strdelimit (g_strdup (cell->cell.value), "-:/\\.", ' ');
+            gchar* menu_copy = g_strdup (menustr);
+            gchar* value_copy = g_strdup (cell->cell.value);
+            g_strdelimit (menu_copy, "-:/\\.", ' ');
+            g_strdelimit (value_copy, "-:/\\.", ' ');
             if (strcmp (menu_copy, value_copy) == 0)
             {
                 gnc_combo_cell_set_value (cell, menustr);



Summary of changes:
 gnucash/gnome-utils/dialog-doclink-utils.c        |  2 +-
 gnucash/gnome/gnc-plugin-page-register.c          | 48 ++++++++++++-----------
 gnucash/gnome/gnc-split-reg.c                     |  4 +-
 gnucash/register/register-gnome/combocell-gnome.c | 16 +++-----
 4 files changed, 33 insertions(+), 37 deletions(-)



More information about the gnucash-changes mailing list