From 4f5ee5dc4e92345f91e06110bb677ab0d15b91c5 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Tue, 9 Apr 2024 00:25:54 +0800 Subject: [PATCH] [dialog-price-edit-db.cpp] plug GList* leaks because `namespace_list` and `commodity_list` were being modified in while loops until they were both nullptr, making g_list_free a nop. rewrite to plug leaks. also, `list` is a PriceList* which needs to be gnc_price_unref'd and g_list_freed. --- gnucash/gnome/dialog-price-edit-db.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gnucash/gnome/dialog-price-edit-db.cpp b/gnucash/gnome/dialog-price-edit-db.cpp index 7d906d95e7..777976b2b5 100644 --- a/gnucash/gnome/dialog-price-edit-db.cpp +++ b/gnucash/gnome/dialog-price-edit-db.cpp @@ -244,14 +244,14 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb) const auto commodity_table = gnc_get_current_commodities (); auto namespace_list = gnc_commodity_table_get_namespaces (commodity_table); - while (namespace_list) + for (auto node_n = namespace_list; node_n; node_n = g_list_next (node_n)) { - auto tmp_namespace = static_cast (namespace_list->data); + auto tmp_namespace = static_cast(node_n->data); DEBUG("Looking at namespace %s", tmp_namespace); auto commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace); - while (commodity_list) + for (auto node_c = commodity_list; node_c; node_c = g_list_next (node_c)) { - auto tmp_commodity = static_cast (commodity_list->data); + auto tmp_commodity = static_cast(node_c->data); auto num = gnc_pricedb_num_prices (pdb, tmp_commodity); DEBUG("Looking at commodity %s, Number of prices %d", gnc_commodity_get_fullname (tmp_commodity), num); @@ -276,12 +276,10 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb) g_free (date_str); g_free (num_str); - gnc_price_unref (price); + g_list_free_full (list, (GDestroyNotify)gnc_price_unref); } - commodity_list = g_list_next (commodity_list); } g_list_free (commodity_list); - namespace_list = g_list_next (namespace_list); } g_list_free (namespace_list);