Re: [xml] xmlParseFile alocates memory and xmlFreeDoc does not free all the memory



On Thu, Dec 02, 2004 at 09:16:10PM +0100, Ioan Paul Pirau wrote:
       //check if the file is valid against it's DTD
       xmlDoValidityCheckingDefaultValue = 1;
       xmlParserCtxtPtr pctxt;
       pctxt = xmlCreateFileParserCtxt(strFileName.c_str());
       xmlParseDocument(pctxt);
       if (!pctxt->valid)
       {
           p_Result = NoBook;
           return;
       }

       doc = xmlParseFile((char*)strFileName.c_str());

       xmlFreeDoc(doc);//clear memory
       xmlCleanupParser();
       xmlMemoryDump();

... and the thing is that xmlFreeDoc does not delete all the memory 
allocated by the calls :

   xmlParseDocument(pctxt);
and
   xmlParseFile((char*)strFileName.c_str());

In my case I use a 2 Mb XML file and the memory leak is quite big ...

  You are parsing the document *twice* !
You are freeing *one* document. You are not freeing pctxt, you look
extremely confused, I suggest you use the examples as guidelines instead of
poking randomly at the API 
   http://xmlsoft.org/examples/index.html#parse2.c

  forget about the code you have shown us and restart from the one 
in the example.

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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