From ca3c09c5f644d0f2f94fb53aa931445631514cab Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 27 Nov 2023 20:53:56 +0800 Subject: [PATCH 1/2] [dialog-report-column-view.cpp] new/delete instead of g_new/g_free because the struct has vector objects which would otherwise leak. --- gnucash/gnome/dialog-report-column-view.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gnucash/gnome/dialog-report-column-view.cpp b/gnucash/gnome/dialog-report-column-view.cpp index 10f772b8ba..fcd6ab988e 100644 --- a/gnucash/gnome/dialog-report-column-view.cpp +++ b/gnucash/gnome/dialog-report-column-view.cpp @@ -61,7 +61,7 @@ using StrVec = std::vector; struct gncp_column_view_edit { - GncOptionsDialog * optwin; + std::unique_ptr optwin; GtkTreeView * available; GtkTreeView * contents; @@ -103,10 +103,9 @@ gnc_column_view_set_option(GncOptionDB* odb, const char* section, static void gnc_column_view_edit_destroy(gnc_column_view_edit * view) { - delete view->optwin; scm_gc_unprotect_object(view->view); gnc_option_db_destroy(view->odb); - g_free(view); + delete view; } static StrVec @@ -322,10 +321,10 @@ gnc_column_view_edit_options(GncOptionDB* odb, SCM view) } else { - gnc_column_view_edit * r = g_new0(gnc_column_view_edit, 1); + auto r = new gnc_column_view_edit; GtkBuilder *builder; - r->optwin = new GncOptionsDialog(nullptr, GTK_WINDOW(gnc_ui_get_main_window (nullptr))); + r->optwin = std::make_unique(nullptr, GTK_WINDOW(gnc_ui_get_main_window (nullptr))); /* Hide the generic dialog page list. */ gtk_widget_hide(r->optwin->get_page_list()); From d8ece96503ccf71550e0d0031bcd936e0af45bd1 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 30 Nov 2023 22:16:53 +0800 Subject: [PATCH 2/2] [gnc-engine-guile.cpp] plug runaway GSList* leak The QofQuery param_list is a GSList of const char*. Every SCM Query would typically leak the GSList. This change will store the params into the string cache, and the cached string is passed onto the QofQuery param. --- bindings/guile/gnc-engine-guile.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/bindings/guile/gnc-engine-guile.cpp b/bindings/guile/gnc-engine-guile.cpp index 39f6d2db40..587674f800 100644 --- a/bindings/guile/gnc-engine-guile.cpp +++ b/bindings/guile/gnc-engine-guile.cpp @@ -386,17 +386,16 @@ gnc_query_scm2path (SCM path_scm) if (!scm_is_list (path_scm)) return nullptr; - while (!scm_is_null (path_scm)) + for (; !scm_is_null (path_scm); path_scm = scm_cdr (path_scm)) { SCM key_scm = SCM_CAR (path_scm); - char *key; if (!scm_is_string (key_scm)) break; - key = gnc_scm_to_utf8_string(key_scm); - path = g_slist_prepend (path, key); - path_scm = SCM_CDR (path_scm); + auto key = gnc_scm_to_utf8_string(key_scm); + path = g_slist_prepend (path, (gpointer)qof_string_cache_insert(key)); + g_free (key); } return g_slist_reverse (path); @@ -405,12 +404,7 @@ gnc_query_scm2path (SCM path_scm) static void gnc_query_path_free (GSList *path) { - GSList *node; - - for (node = path; node; node = node->next) - g_free (node->data); - - g_slist_free (path); + g_slist_free_full (path, (GDestroyNotify)qof_string_cache_remove); }