[xml] Help, but this looks like a massive memory leak



Am I the only one using this code that is experiencing a major memory leak?

I performed the following experiment that is easily duplicated, and I
provide the code below to do so.

The code is a near exact implementation of the code as suggested
in 
           "The XML C library for Gnome"
section:   "Invoking the parser: the push method"

except that I added code to test for parse errors.

The idea is to  
        1) read a file
        2) parse it
        3) release all memory using  xmlParseChunk
        4) close the file
        repeat 10 times on the same file.

As I understand the documentation, I only need to call
xmlParseChunk  to free everything created by xmlCreatePushParserCtxt
and xmlParseChunk.   If this is not true, then the documentation
needs to be corrected.   If this is true, it sure looks like a massive
leak to me.

If one could count all the mallocs plus strdups, the result
should be exactly equall to the "free"s.    Ignoring any 
the use of realloc.

At least that is my understanding of how malloc and free
relate to one another.

As it turns out it is not difficult to do this counting.  Simply tweak
xmlmemory.c as shown in my code example: leak.
To me it looks like there are 2 mallocs for ever free.




Perhaps I am an idiot, but I made this code as close to the
documented recommendation as possible, but the number
of malloc's for exceeds the number of frees and not by just
a little bit.   

I did this on the QNX  OS, if anyone out there could perform
this test on a different OS, I would appreciate knowing if QNX
has a problem.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-   
Stanley J. Boehm, Senior Software Engineer
Center for Industrial Technology
Sunnyvale, CA  94085-2810

Phone:  (408) 617-2483                  E-mail:  Stan Boehm philips com      
FAX  :     (408) 617-7711
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Attachment: leak
Description: Binary data

Attachment: exhibit_a
Description: Binary data

Attachment: exhibit_b
Description: Binary data



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