Monday, February 13, 2012

A few words about xmlCleanupParser

Today I wrote an application which uses both libxml2 and GStreamer. It crashed for some mysterious reason which turned out to be xmlCleanupParser called twice. Damn it, it turns out that the only reason for that function to exist is getting rid of valgrind messages!

This frees up a few global variables allocated by libxml2. A few
kilobytes at most, but if they get deallocated while somehow the library
is still in use, the application is very likely to crash.
  So never call this in a library.
  In an app the only safe place to call it is close to the exit
It's still useful to make sure there is no memory leak when running a
program under valgrind or equivalent memory checker.
(http://mail.gnome.org/archives/xml/2011-April/msg00048.html)

Cool, huh?!

I think it's worthwhile to emphasize the thought:

NEVER EVER FUCKING CALL xmlCleanupParser() IN A LIBRARY!