From 0d326fa100b79bbc71884860b2451fb2f2509538 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 1 Jul 2023 11:43:27 +0800 Subject: [PATCH] [io-gncxml-v2.cpp] plug g_strdup leak --- libgnucash/backend/xml/io-gncxml-v2.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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);