From 6bf5a618debee47d90317ff287767ba6d1fd32fa Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 13 Aug 2021 23:33:03 +0800 Subject: [PATCH] qof_instance_get gchar* must be freed A call to qof_instance_get expecting a gchar* receives a newly allocated string which must be freed. --- gnucash/gnome-utils/gnc-tree-view-account.c | 3 ++- gnucash/gnome/gnc-plugin-page-report.c | 17 ++++++++++------- libgnucash/engine/qofbook.cpp | 12 +++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c index 0c7a79f150..9049213651 100644 --- a/gnucash/gnome-utils/gnc-tree-view-account.c +++ b/gnucash/gnome-utils/gnc-tree-view-account.c @@ -1866,9 +1866,10 @@ account_cell_property_data_func (GtkTreeViewColumn *tree_column, account = gnc_tree_view_account_get_account_from_iter(s_model, s_iter); qof_instance_get (QOF_INSTANCE (account), key, &string, NULL); if (string == NULL) - string = ""; + string = g_strdup (""); g_object_set (G_OBJECT (cell), "text", string, "xalign", 0.0, NULL); + g_free (string); view = g_object_get_data(G_OBJECT(tree_column), "tree-view"); diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c index dff95509de..e8a37b0460 100644 --- a/gnucash/gnome/gnc-plugin-page-report.c +++ b/gnucash/gnome/gnc-plugin-page-report.c @@ -1965,13 +1965,16 @@ gnc_plugin_page_report_exportpdf_cb( GtkAction *action, GncPluginPageReport *rep // Yes. In the kvp, look up the key for the Export-PDF output // directory. If it exists, prepend this to the job name so that // we can export to PDF. - if (dirname && g_file_test(dirname, - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) - { - gchar *tmp = g_build_filename(dirname, job_name, NULL); - g_free(job_name); - job_name = tmp; - } + if (dirname) + { + if (g_file_test (dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) + { + gchar *tmp = g_build_filename (dirname, job_name, NULL); + g_free (job_name); + job_name = tmp; + } + g_free (dirname); + } } } diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp index 9d3925adfc..ab2b012319 100644 --- a/libgnucash/engine/qofbook.cpp +++ b/libgnucash/engine/qofbook.cpp @@ -1032,13 +1032,11 @@ qof_book_get_default_gain_loss_acct_guid (QofBook *book) gboolean qof_book_use_trading_accounts (const QofBook *book) { - const char *opt = NULL; - qof_instance_get (QOF_INSTANCE (book), - "trading-accts", &opt, - NULL); - if (opt && opt[0] == 't' && opt[1] == 0) - return TRUE; - return FALSE; + char *opt = nullptr; + qof_instance_get (QOF_INSTANCE (book), "trading-accts", &opt, nullptr); + auto retval = (opt && opt[0] == 't' && opt[1] == 0); + g_free (opt); + return retval; } /* Returns TRUE if this book uses split action field as the 'Num' field, FALSE