gnucash stable: [io-gncxml-v2.cpp] plug g_strdup leak

Christopher Lam clam at code.gnucash.org
Sat Jul 1 00:00:03 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/0d326fa1 (commit)
	from  https://github.com/Gnucash/gnucash/commit/c313c3de (commit)



commit 0d326fa100b79bbc71884860b2451fb2f2509538
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 1 11:43:27 2023 +0800

    [io-gncxml-v2.cpp] plug g_strdup leak

diff --git a/libgnucash/backend/xml/io-gncxml-v2.cpp b/libgnucash/backend/xml/io-gncxml-v2.cpp
index 2615f07d2a..193fb7a544 100644
--- a/libgnucash/backend/xml/io-gncxml-v2.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v2.cpp
@@ -872,11 +872,11 @@ static gboolean
 write_counts (FILE* out, ...)
 {
     va_list ap;
-    char* type;
+    const char* type;
     gboolean success = TRUE;
 
     va_start (ap, out);
-    type = g_strdup (va_arg (ap, char*));
+    type = va_arg (ap, char*);
 
     while (success && type)
     {
@@ -885,6 +885,7 @@ write_counts (FILE* out, ...)
         if (amount != 0)
         {
 #if GNUCASH_REALLY_BUILD_AN_XML_TREE_ON_OUTPUT
+            char *type_dup = g_strdup (type);
             char* val;
             xmlNodePtr node;
 
@@ -896,10 +897,10 @@ write_counts (FILE* out, ...)
              * This is invalid xml because the namespace isn't
              * declared in the tag itself. This should be changed to
              * 'type' at some point. */
-            xmlSetProp (node, BAD_CAST "cd:type", checked_char_cast (type));
+            xmlSetProp (node, BAD_CAST "cd:type", checked_char_cast (type_dup));
             xmlNodeAddContent (node, checked_char_cast (val));
             g_free (val);
-            g_free (type);
+            g_free (type_dup);
 
             xmlElemDump (out, NULL, node);
             xmlFreeNode (node);



Summary of changes:
 libgnucash/backend/xml/io-gncxml-v2.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)



More information about the gnucash-changes mailing list