gnucash stable: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Thu Nov 28 06:02:40 EST 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/ec0d2619 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5661c45d (commit)
	from  https://github.com/Gnucash/gnucash/commit/64a319eb (commit)



commit ec0d2619e97e22e14350fcdcf6b4721c2aa96ea7
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 08:27:46 2024 +0800

    gnc_commodity_table_get_commodities must be g_list_freed
    
    the previous g_list_free was being called at the wrong scope, and
    commodity_list was NULL anyway at the end of the loop.

diff --git a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
index 24699d2244..3543b51747 100644
--- a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
+++ b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
@@ -447,7 +447,6 @@ GtkTreeModel *get_model (bool all_commodity)
     const gnc_commodity_table *commodity_table = gnc_get_current_commodities ();
     gnc_commodity *tmp_commodity = nullptr;
     char  *tmp_namespace = nullptr;
-    GList *commodity_list = nullptr;
     GList *namespace_list = gnc_commodity_table_get_namespaces (commodity_table);
     GtkTreeIter iter;
 
@@ -471,8 +470,7 @@ GtkTreeModel *get_model (bool all_commodity)
         {
             if ((g_utf8_collate (tmp_namespace, GNC_COMMODITY_NS_CURRENCY ) == 0) || (all_commodity == true))
             {
-                commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
-                commodity_list  = g_list_first (commodity_list);
+                auto comm_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
 
                 // if this is the CURRENCY, add a row to be identified as a separator row
                 if ((g_utf8_collate (tmp_namespace, GNC_COMMODITY_NS_CURRENCY) == 0) && (all_commodity == true))
@@ -482,11 +480,11 @@ GtkTreeModel *get_model (bool all_commodity)
                                            SORT_COMM, "CURRENCY-", COMM_PTR, nullptr, SEP, true, -1);
                 }
 
-                while (commodity_list != nullptr)
+                for (auto node = comm_list; node; node = g_list_next (node))
                 {
                     const gchar *name_str;
                     gchar *sort_str;
-                    tmp_commodity = (gnc_commodity*)commodity_list->data;
+                    tmp_commodity = (gnc_commodity*)node->data;
                     DEBUG("Looking at commodity %s", gnc_commodity_get_fullname (tmp_commodity));
 
                     name_str = gnc_commodity_get_printname (tmp_commodity);
@@ -503,12 +501,11 @@ GtkTreeModel *get_model (bool all_commodity)
                                            SORT_COMM, sort_str, COMM_PTR, tmp_commodity, SEP, false, -1);
 
                     g_free (sort_str);
-                    commodity_list = g_list_next (commodity_list);
                 }
+                g_list_free (comm_list);
             }
         }
     }
-    g_list_free (commodity_list);
     g_list_free (namespace_list);
     g_object_unref (store);
 

commit 5661c45d2a843c88859443e977c01d74316cca00
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 08:21:59 2024 +0800

    gnc_commodity_table_get_namespaces must be g_list_freed

diff --git a/bindings/guile/gnc-optiondb.i b/bindings/guile/gnc-optiondb.i
index 3f69876a19..5e8a3df693 100644
--- a/bindings/guile/gnc-optiondb.i
+++ b/bindings/guile/gnc-optiondb.i
@@ -1979,6 +1979,7 @@ gnc_register_multichoice_callback_option(GncOptionDBPtr& db,
         const auto book{qof_session_get_book(gnc_get_current_session())};
         const auto commodity_table{gnc_commodity_table_get_table(book)};
         const auto namespaces{gnc_commodity_table_get_namespaces(commodity_table)};
+        GncOption* rv = nullptr;
         for (auto node = namespaces; node && commodity == nullptr;
              node = g_list_next(node))
         {
@@ -1987,10 +1988,13 @@ gnc_register_multichoice_callback_option(GncOptionDBPtr& db,
                                                    value);
 
             if (commodity)
-                return gnc_make_commodity_option(section, name, key, doc_string,
-                                                 commodity);
+            {
+                rv = gnc_make_commodity_option(section, name, key, doc_string, commodity);
+                break;
+            }
         }
-        return nullptr;
+        g_list_free (namespaces);
+        return rv;
     }
 
     static GncOption*
diff --git a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
index 6f1a8644dd..24699d2244 100644
--- a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
+++ b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
@@ -461,10 +461,9 @@ GtkTreeModel *get_model (bool all_commodity)
     gtk_list_store_set (GTK_LIST_STORE(store), &iter,
                             DISPLAYED_COMM, " ", SORT_COMM, " ", COMM_PTR, nullptr, SEP, false, -1);
 
-    namespace_list = g_list_first (namespace_list);
-    while (namespace_list != nullptr)
+    for (auto node = namespace_list; node; node = g_list_next (node))
     {
-        tmp_namespace = (char*)namespace_list->data;
+        tmp_namespace = (char*)node->data;
         DEBUG("Looking at namespace %s", tmp_namespace);
 
         /* Hide the template entry */
@@ -508,7 +507,6 @@ GtkTreeModel *get_model (bool all_commodity)
                 }
             }
         }
-        namespace_list = g_list_next (namespace_list);
     }
     g_list_free (commodity_list);
     g_list_free (namespace_list);
diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
index 49ab27ab35..760623b943 100644
--- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
+++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp
@@ -213,6 +213,7 @@ gnc_commodity* parse_commodity (const std::string& comm_str)
             if (comm)
                 break;
         }
+        g_list_free (namespaces);
     }
 
     if (!comm)
diff --git a/libgnucash/engine/gnc-optiondb.cpp b/libgnucash/engine/gnc-optiondb.cpp
index f423164db7..17d23d8fb6 100644
--- a/libgnucash/engine/gnc-optiondb.cpp
+++ b/libgnucash/engine/gnc-optiondb.cpp
@@ -707,6 +707,7 @@ gnc_register_commodity_option(GncOptionDB* db, const char* section,
                 commodity,
                 GncOptionUIType::COMMODITY}};
     db->register_option(section, std::move(option));
+    g_list_free (namespaces);
 }
 
 void



Summary of changes:
 bindings/guile/gnc-optiondb.i                           | 10 +++++++---
 .../csv-imp/assistant-csv-price-import.cpp              | 17 ++++++-----------
 gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp      |  1 +
 libgnucash/engine/gnc-optiondb.cpp                      |  1 +
 4 files changed, 15 insertions(+), 14 deletions(-)



More information about the gnucash-changes mailing list