RE: [xml] xmlParseFile, does this allocate memory?



Ah.. I just noticed they relased a new patch to valgrind(2.1.2) grabbed
that and it no longer reports a leak on that call in  libxml2. So
chances are it was just a bug with valgrind in this case.

Am I correct to asume I do not need to call xmlFreeDoc on the xmlDocPtr
that xmlParseFile returns?

Thanks
-grant


-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On Behalf Of
Grant Schoep
Sent: Wednesday, July 21, 2004 2:12 PM
To: xml gnome org
Subject: [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
itself.

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");
xmlFreeDoc(doc);
-

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
(vg_libpthread.c:1628)
==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
/usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C0B71D8: __xmlGenericError (in
/usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C060B09: xmlInitParser (in
/usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C060332: xmlSAXParseFileWithData (in
/usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C060454: xmlSAXParseFile (in
/usr/lib/libxml2.so.2.5.10)
==13162==    by 0x3C0604CE: xmlParseFile (in /usr/lib/libxml2.so.2.5.10)
==13162==    by 0x804A27C: main (tbm.cxx:12)

Any ideas?
-grant
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml



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