@@ -83,6 +83,8 @@ void readNode(xmlNodePtr root, Config *config)
8383*/
8484void writeNode (xmlTextWriterPtr writer, const Config *config, const std::string &encoding)
8585{
86+ int status;
87+
8688 // Write the options
8789 for (const auto &entry : config->getOptions ()) {
8890 const std::string &key = entry.first ;
@@ -91,6 +93,12 @@ void writeNode(xmlTextWriterPtr writer, const Config *config, const std::string
9193 xmlChar *elementName = encodeString (key, encoding);
9294 xmlChar *elementText = encodeString (value, encoding);
9395 int status = xmlTextWriterWriteFormatElement (writer, BAD_CAST elementName, " %s" , elementText);
96+ if (elementText) {
97+ xmlFree (elementText);
98+ }
99+ if (elementName) {
100+ xmlFree (elementName);
101+ }
94102 if (status < 0 ) {
95103 throw std::runtime_error (" Error at xmlTextWriterWriteFormatElement" );
96104 }
@@ -103,7 +111,10 @@ void writeNode(xmlTextWriterPtr writer, const Config *config, const std::string
103111
104112 // Start the section
105113 xmlChar *elementName = encodeString (key, encoding);
106- int status = xmlTextWriterStartElement (writer, BAD_CAST elementName);
114+ status = xmlTextWriterStartElement (writer, BAD_CAST elementName);
115+ if (elementName) {
116+ xmlFree (elementName);
117+ }
107118 if (status < 0 ) {
108119 throw std::runtime_error (" Error at xmlTextWriterStartElement" );
109120 }
@@ -250,6 +261,9 @@ void writeConfiguration(const std::string &filename, const std::string &rootname
250261 // Start the root element
251262 xmlChar *elementName = encodeString (rootname, DEFAULT_ENCODING);
252263 status = xmlTextWriterStartElement (writer, BAD_CAST elementName);
264+ if (elementName) {
265+ xmlFree (elementName);
266+ }
253267 if (status < 0 ) {
254268 throw std::runtime_error (" Error at xmlTextWriterStartElement" );
255269 }
@@ -260,6 +274,9 @@ void writeConfiguration(const std::string &filename, const std::string &rootname
260274
261275 xmlChar *versionAttr = encodeString (versionStream.str (), DEFAULT_ENCODING);
262276 status = xmlTextWriterWriteAttribute (writer, BAD_CAST " version" , BAD_CAST versionAttr);
277+ if (versionAttr) {
278+ xmlFree (versionAttr);
279+ }
263280 if (status < 0 ) {
264281 throw std::runtime_error (" Error at xmlTextWriterWriteAttribute" );
265282 }
0 commit comments