[xml] xmlParseFile, does this allocate memory?

I just inherited a code base and it is using the libxml2 libraries. At
one point it is using xmlParseFile(), while analyzing the program  with
valgrind(program like Purify for memory issues) I see what looks to be a
leak with xmlParseFile(), most likely how I am using it, not the libxml2

It is simply doing a xmlParseFile() call, which returns an xmlDocPtr.
Looking at the API for this call, it doesn't say anything about
xmlParseFile allocating memory that the caller must free. Should I? With
my xml config file, if I do a xmlFreeDoc() on the returned pointer, or
do not do it. It leaks 200 bytes regardless. 

It is the call to xmlParseFile that is allocating memory, there is
nothing else in my simple main(). 

i.e. the only code in the program is this( I stripped it down to narrow
the other factors out)
xmlDocPtr doc = xmlParseFile("./myFile");

So my question is, do I need to call xmlFreeDoc on this? If so, why is
it still leaking memory? If not, what is the proper way to clean up what
xmlDocPtr allocates.

valgrind gives me a stack output from the xmlParseFile as follows.

==13162==    at 0x3C01E42D: malloc (vg_replace_malloc.c:105)
==13162==    by 0x3C348E85: my_malloc (vg_libpthread.c:334)
==13162==    by 0x3C34C0EC: get_or_allocate_specifics_ptr
(vg_libpthread.c:1591)==13162==    by 0x3C34C2A0: pthread_key_create
==13162==    by 0x3C0B7D5B: (within /usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C34C9E5: pthread_once (vg_libpthread.c:1730)
==13162==    by 0x3C0B7C8B: xmlIsMainThread (in
==13162==    by 0x3C0B71D8: __xmlGenericError (in
==13162==    by 0x3C060B09: xmlInitParser (in
==13162==    by 0x3C060332: xmlSAXParseFileWithData (in
==13162==    by 0x3C060454: xmlSAXParseFile (in
==13162==    by 0x3C0604CE: xmlParseFile (in /usr/lib/libxml2.so.2.5.10)
==13162==    by 0x804A27C: main (tbm.cxx:12)

Any ideas?

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