Skip to content

Conversation

stbergmann
Copy link
Contributor

Despite its name, it is a cleanup function for libxml2 that must only be called
when the process as a whole no longer needs libxml2. Calling it from a library
like liblangtag is not appropriate (just like liblangtag does not call
xmlInitParser, either).

In LibreOffice, this caused confusion about pthread keys for thread-local
storage (xmlCleanupParser calls pthread_key_delete, but apparently if libxml2 is
later used by unrelated code in LibreOffice again, it still uses the stale key,
and if that key is now reused via an unrelated pthread_key_create, arbitrary
crashes happen during thread termination in pthread's __nptl_deallocate_tsd),
cf. <http://cgit.freedesktop.org/libreoffice/core/commit/
?id=5e6c595e9d698caf23ae68d38b9cab30ff9c9b94> "Do not call xmlCleanupParser from
liblangtag."

Despite its name, it is a cleanup function for libxml2 that must only be called
when the process as a whole no longer needs libxml2.  Calling it from a library
like liblangtag is not appropriate (just like liblangtag does not call
xmlInitParser, either).

In LibreOffice, this caused confusion about pthread keys for thread-local
storage (xmlCleanupParser calls pthread_key_delete, but apparently if libxml2 is
later used by unrelated code in LibreOffice again, it still uses the stale key,
and if that key is now reused via an unrelated pthread_key_create, arbitrary
crashes happen during thread termination in pthread's __nptl_deallocate_tsd),
cf. <http://cgit.freedesktop.org/libreoffice/core/commit/
?id=5e6c595e9d698caf23ae68d38b9cab30ff9c9b94> "Do not call xmlCleanupParser from
liblangtag."
@tagoh
Copy link
Owner

tagoh commented Sep 20, 2012

Aha. but I see there are some memory leaks without it. I'm not quite sure if there are any way to clean it up.

@stbergmann
Copy link
Contributor Author

"I'm not quite sure if there are any way to clean it up.": I fear there is no way for the library to clean it up, that rather the design of libxml2 requires that once it is used in a program, and may potentially be used again, then its fundamental (not per-document) resources can only be reclaimed at program exit. See e.g. the discussion at https://bugzilla.redhat.com/show_bug.cgi?id=554903" Please print a warning (or abort) if xmlCleanupParser() is called twice."

tagoh added a commit that referenced this pull request Sep 21, 2012
Do not call xmlCleanupParser from liblangtag
@tagoh tagoh merged commit f11c34c into tagoh:master Sep 21, 2012
@ghost ghost assigned tagoh Sep 21, 2012
@tagoh
Copy link
Owner

tagoh commented Sep 21, 2012

Okay. thanks for explanation and patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants