[Expat-discuss] XML_ParserReset and memory leak??
Karl Waclawek
karl@waclawek.net
Fri Aug 16 19:01:02 2002
> Hi,
>
> I using the XML_ParseReset function and seeing a memory leak. I am not sure
> if I am using it incorrecly or if there is a bug. The leak can be observed
> by using the windows task Manager. Below is a simple sample application.
> Thanks for your feedback.
>
> Expat version: 1.95.4
> Platform: win200
>
> ajit
>
>
> include <string.h>
> #include "expat.h"
>
> char buffer[] = "<?xml version=\"1.0\"?><request
> version=\"1.00\"></request>";
>
> void main()
> {
> XML_Parser parser = XML_ParserCreate(NULL);
>
> while ( true )
> {
> int ret = XML_Parse( parser, buffer, strlen(buffer ), 1);
> if( ret == 0 )
> {
> abort();
> }
>
> ret = XML_ParserReset( parser, NULL );
> if( ret == 0 )
> {
> abort();
> }
> }
> }
You still need to call XML_ParserFree.
XML_ParserReset just allows you to re-use
the same parser instance for additional runs.
In any case, your use of abort() would produce
memory leaks anyway, since XML_ParserFree would
not get called in that case.
I recommend you check the HTML documentation
(reference.html) which has some sample code
for the main parsing loop.
Karl