Heads-Up: Beware of xmlCleanupParser() when your package links against libxml2

Lennart Poettering mzerqung at 0pointer.de
Wed Jan 13 20:26:26 UTC 2010


On Wed, 13.01.10 16:00, Daniel Veillard (veillard at redhat.com) wrote:

> > Afaik it does, i agree with Lennart that a warning from libxml2 would be
> > welcome.
> 
>   The problem is that you can perfectly have application not relying on
> libxml2 outside of their own code use libxml2 at different phases,
> for example when parsing input, and when generating result, not using
> the library in the meantime and calling xmlCleanupParser() twice (or
> more) in a perfectly legal way.
> 
>   And there is nothing more frustrating than a library outputting
> a warning to some uncontrolled channel, because it thinks it's
> appropriate to do so, but making the user mad because the programmer
> might have made a mistake (or not). Latest fun example being

Hmm, given that probably the majority of the libxml2 users are
misusing it, and misusing is an actual bug that caused program aborts
due to TLS vars being released that shouldn't i wonder if printing a
msg if this might happen is that bad. I mean if the options are "be
unstable but be quiet" or "be unstable and print a msg", then I'd vote
for the second choice...

There's something else that came to my mind: if libxml2 is loaded into
memory indirectly because some dlopen'ed module wanted it, and then
used, and then unloaded again because the module got dlcose'd again,
won't you leak TLS vars unless the xmlCleanupParser() function was
called properly before? In that case, not calling xmlCleanupParser()
is an error, right? And calling it, too, since some other
plugin/thread might still need it. Which means you are in a dilemma:
in either case you are doing it wrong.

(-z nodelete linking for libxml2 might be the solution for this prob,
but I guess the fact is simply that the existance of
xmlCleanupParser() in itself is probably not a good idea)

If you don't want to print a msg during runtime, maybe it could be an
option to use link time warnings? that way developers should see the
warning, but during runtime it will not be visible:

#if defined(__GNUC__) && defined(__ELF__)
#define WARN_REFERENCE(sym, msg)                     \
    __asm__(".section .gnu.warning." #sym);          \
    __asm__(".asciz \"" msg "\"");                   \
    __asm__(".previous")
#else
#define WARN_REFERENCE(sym, msg)
#endif

And then simply use something like this:

WARN_REFERENCE(xmlCleanupParser, "You are probably misusing xmlCleanupParser().");

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/           GnuPG 0x1A015CC4


More information about the devel mailing list