[xml] how to clean up properly after SAX parsing



Hi,

I'm just figuring out how to do some simple SAX parsing with libxml
(version 2.6.29, Debian unstable).  I haven't tried using this from C
before, so I'm probably making simple mistakes.

Valgrind is telling me I've got a leak.  Am I missing some sort of
memory clean-up call?

This is roughly what I've got (some of the handlers are NULL, the ones
I do have just print some debugging info for now):

    f = fopen(filename, "rb"); 
    ret = fread(chars, 1, 4, f);
    ctxt = xmlCreatePushParserCtxt(&sax_handlers, 0, chars, ret, filename);

    while ((ret = fread(chars, 1, 3, f)) > 0)
        xmlParseChunk(ctxt, chars, ret, 0);
    ret = xmlParseChunk(ctxt, chars, 0, 1);

    xmlFreeParserCtxt(ctxt);
    if (ret != 0)
        fprintf(stderr, "xmlSAXUserParseFile returned error %d\n", ret);
    fclose(f);

The blocks of memory which are being leaked were allocated by
xmlCreatePushParserCtxt().

Any ideas?

thanks,
    Geoff

-- 

--- Geoff Richards -------------><-------------- http://ungwe.org/ ---
"I tried to fling my shadow at the moon,
 The while my blood leapt with a wordless song."  --  Theodore Roethke



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