[xml] memory leak in xmlTextWriter?



Hi,

Last week I reported a possible bug in xmlTextWriter (bug #131368), 

this is the testcase:
-----------------------------------------------------------
#include <libxml/xmlwriter.h>
#include <libxml/xmlmemory.h>

int main(void)
{
 xmlTextWriterPtr writer;
 xmlDocPtr doc;
 LIBXML_TEST_VERSION;
 writer = xmlNewTextWriterDoc(&doc, 0);
 xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
 xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
 xmlTextWriterEndElement(writer);
 xmlTextWriterEndDocument(writer);
 xmlFreeTextWriter(writer);

 xmlFreeDoc(doc);
 xmlCleanupParser();
 xmlMemoryDump();
 return 0;
}
-----------------------------------------------------------
Building against cvs-snapshot from today (2004-01-20) under Windows 2000,VC++6.0 with:
mem_debug=yes iconv=no threads=no debug=yes

The testcase program generates the following .memdump file:
-----------------------------------------------------------
      MEMORY ALLOCATED : 12230, MAX was 16972
BLOCK  NUMBER   SIZE  TYPE
0          47     10 malloc()  in none(0) "1.0"
1          46   1024 malloc()  in none(0)
2          42      2 malloc()  in none(0) " "
3          31     60 malloc()  in none(0) pointer to #18 at index 0
4          30    128 malloc()  in none(0)
5          29    120 malloc()  in none(0)
6          28     40 malloc()  in none(0)
7          27     40 malloc()  in none(0)
8          26     40 malloc()  in none(0)
9          25     20 malloc()  in none(0) "0n/"
10         23   2048 malloc()  in none(0)
11         22     20 malloc()  in none(0) pointer to #23 at index 4
12         21    436 malloc()  in none(0) pointer to #30 at index 0
13         20   8194 malloc()  in none(0) [<?xml version="1.0"?>]
14         19     16 malloc()  in none(0) pointer to #20 at index 0
15         18     32 malloc()  in none(0) pointer to #19 at index 16
-----------------------------------------------------------

I ran the testcase code inside a loop and the memory increases about 12K per iteration, so it seems it's a 
memory leak.

Am I misusing xmlTextWriter?

If the answer is no, I think that the memory leaked is allocated in function xmlAllocParserInputBuffer 
(xmlIO.c) line 1960, this is the call stack (line numbers refer to cvs-snapshot 2004-01-20):

xmlAllocParserInputBuffer(int 0) [xmlIO.c, line 1960]

xmlCreatePushParserCtxt(_xmlSAXHandler * 0x0012fe9c, void * 0x00000000, const char * 0x00000000, int 0, const 
char * 0x00000000) [parser.c, line 9750]

xmlNewTextWriterDoc(_xmlDoc * * 0x0012ff78, int 0) [xmlwriter.c, line 277]

main() [line 11]

Of course the leak is not in xmlIO.c or parser.c, but my understanding of xmlTextWriter isn't enough to be 
able to provide a patch for xmlwriter.c.

Could anybody give me a hint, please?

Thanks,
Manuel





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]