Re: [xml] calling xmlCleanupParser from a library considered harmful



On 30/10/12 03:07, Daniel Veillard wrote:
On Mon, Oct 01, 2012 at 05:30:37PM +0200, Michael Stahl wrote:

hi all,

authors of libraries that use libxml2 internally for whatever reason
should take note that calling xmlCleanupParser frees various bits of
global state and as a result makes libxml2 effectively unusable for any
other code in the process that also happens to use libxml2, and hence
makes your library effectively un-usable (until the offending call is
patched out).

 yeah, it's painful, but that function is needed in some ways to
avoid what is reported as a data leak if using valgrind for example.
As you pointed out I have tried to make the documentation as explicit
as possible, but you know how much people read those ;-)

 Except doing something like introducing a call like
  xmlProgramIsAboutToExit()
and then checking that this call has been called before allowing
xmlCleanupParser() to effectively work, I don't see how to make sure
people change their code.
 Doing this would be possible, it would change the API semantic,
but would get rid of the issue. It could be made strong by requiring
a program name as an argument (and on linux we could do some checking)
but it's probably superfluous, the extra call should be sufficient.

  Opinions about this ?

yes, that would probably be an improvement (or the ~equivalent of
replacing xmlCleanupParser with NOP and adding new xmlReallyCleanupStuff
suggested in the other mail).

one problem we've had with my xmlCleanupParser override (for debug
purposes) was that there was some KDE library that registers
xmlCleanupParser as an atexit() handler, which i didn't expect :)

it seems to me that it is not actually sound (in theory) to ever call
xmlCleanupParser, because the atexit() handlers are run in reverse order
of registration, so there is no way to express a dependency there, and
it is possible for an atexit() handler registered anywhere to call
libxml2 functions that require it to be initialized; i wonder if anybody
would be crazy enough to do that in practice.

in case we agree that calling libxml2 functions from atexit() handlers
is not at all supported (i'm not really familiar with what's allowed in
that context anyway), it would also be possible that libxml2's xmlInit()
function register an atexit() handler that does the actual cleanup.  or
are there additional problems there that would come up?

regards,
 michael





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