gnucash stable: [gnucash-commands.cpp] plug some char* leaks

Christopher Lam clam at code.gnucash.org
Mon Oct 16 01:18:11 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/d25fb50b (commit)
	from  https://github.com/Gnucash/gnucash/commit/8046eb2c (commit)



commit d25fb50b2cc1cfc73d94db94b7ea38dcbe4208b2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Oct 16 12:06:26 2023 +0800

    [gnucash-commands.cpp] plug some char* leaks

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 7f1fe371d3..0ff5896ce1 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -172,8 +172,6 @@ scm_run_report (void *data,
     if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
         scm_cleanup_and_exit_with_failure (session);
 
-    char *output;
-
     if (!args->export_type.empty())
     {
         SCM retval = scm_call_2 (run_export_cmd, report, type);
@@ -193,7 +191,7 @@ return a document object with export-string or export-error.") << std::endl;
 
         if (scm_is_string (export_string))
         {
-            output = scm_to_utf8_string (export_string);
+            auto output = scm_to_utf8_string (export_string);
             if (!args->output_file.empty())
             {
                 write_report_file(output, args->output_file.c_str());
@@ -202,11 +200,13 @@ return a document object with export-string or export-error.") << std::endl;
             {
                 std::cout << output << std::endl;
             }
+            g_free (output);
         }
         else if (scm_is_string (export_error))
         {
             auto err = scm_to_utf8_string (export_error);
             std::cerr << err << std::endl;
+            g_free (err);
             scm_cleanup_and_exit_with_failure (nullptr);
         }
         else
@@ -234,10 +234,12 @@ return a document object with export-string or export-error.") << std::endl;
             {
                 std::cout << html << std::endl;
             }
+            g_free (html);
         }
         else
         {
             std::cerr << errmsg << std::endl;
+            g_free (errmsg);
         }
     }
 



Summary of changes:
 gnucash/gnucash-commands.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list