Re: [xml] how to clean up properly after SAX parsing

On Tue, Jul 10, 2007 at 12:00:11PM +0100, Geoff Richards wrote:

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);

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

The blocks of memory which are being leaked were allocated by

Any ideas?

  1/ read the docs
  2/ use testSAX.c from the distribution as example
     valgrind --leak-check=full testSAX --push test/isolat3
     works just fine for me
  3/ do NOT use SAX unless you REALLY need it, use the reader or
     the tree API.


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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