On Tue, Jul 10, 2007 at 12:00:11PM +0100, Geoff Richards wrote:
> 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?
1/ read the docs
http://xmlsoft.org/xmlmem.html
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.
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
[EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml