gnucash maint: qof_instance_get gchar* must be freed

Christopher Lam clam at code.gnucash.org
Sat Aug 14 22:24:20 EDT 2021


Updated	 via  https://github.com/Gnucash/gnucash/commit/6bf5a618 (commit)
	from  https://github.com/Gnucash/gnucash/commit/e4d808e6 (commit)



commit 6bf5a618debee47d90317ff287767ba6d1fd32fa
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Aug 13 23:33:03 2021 +0800

    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.

diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index 0c7a79f15..904921365 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 dff95509d..e8a37b046 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 9d3925adf..ab2b01231 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



Summary of changes:
 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(-)



More information about the gnucash-changes mailing list