[xml] Memory leak in tree.c

Date view Thread view Subject view Author view

From: Steve Ratcliffe (steve@parabola.demon.co.uk)
Date: Tue Jun 08 1999 - 14:46:12 EDT


I also have an app that builds up a tree only to print it out. With 1.0.0
this took ~3 seconds and used 18M of memory for a 25000 node tree giving
an output file size of a little over 1M.

With 1.1.0 it took an unacceptable amount of time and memory usage
swelled to 103M!

Tracked this down to a memory leak, patch below (this may not be the
best fix of course). Performance is now on a par with 1.0.0.

Cheers,
..Steve

--- tree.c.ORIG Tue Jun 8 19:10:46 1999
+++ tree.c Tue Jun 8 19:17:31 1999
@@ -675,8 +675,12 @@
         if (node->type == XML_TEXT_NODE) {
             if (inLine)
                 ret = xmlStrcat(ret, node->content);
- else
- ret = xmlStrcat(ret, xmlEncodeEntities(doc, node->content));
+ else {
+ CHAR *tmp;
+ tmp = xmlEncodeEntities(doc, node->content);
+ ret = xmlStrcat(ret, tmp);
+ free(tmp);
+ }
         } else if (node->type == XML_ENTITY_REF_NODE) {
             if (inLine) {
                 ent = xmlGetDocEntity(doc, node->name);
@@ -2568,8 +2572,12 @@
         return;
     }
     if (cur->type == XML_TEXT_NODE) {
- if (cur->content != NULL)
- xmlBufferWriteCHAR(buf, xmlEncodeEntities(doc, cur->content));
+ if (cur->content != NULL) {
+ CHAR *tmp;
+ tmp = xmlEncodeEntities(doc, cur->content);
+ xmlBufferWriteCHAR(buf, tmp);
+ free(tmp);
+ }
         return;
     }
     if (cur->type == XML_COMMENT_NODE) {
@@ -2607,8 +2615,12 @@
         return;
     }
     xmlBufferWriteChar(buf, ">");
- if (cur->content != NULL)
- xmlBufferWriteCHAR(buf, xmlEncodeEntities(doc, cur->content));
+ if (cur->content != NULL) {
+ CHAR *tmp;
+ tmp = xmlEncodeEntities(doc, cur->content);
+ xmlBufferWriteCHAR(buf, tmp);
+ free(tmp);
+ }
     if (cur->childs != NULL) {
         xmlNodeListDump(buf, doc, cur->childs, level + 1);
     }

----
Message from the list xml@rufus.w3.org
Archived at : http://rufus.w3.org/veillard/XML/messages
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rufus.w3.org


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 02 2000 - 12:29:38 EDT