michaelrsweet/mxml

shared library cleanup problem

scott-snyder opened this issue · 5 comments

hi -

I ran into an issue in fedora 36 where the rosegarden sequencer would
crash on startup with a report of EINVAL from pthread_setspecific.
See https://bugzilla.redhat.com/show_bug.cgi?id=2089032.
The root cause appears to be mxml. In brief:
rosegarden scans a set of plugins at startup, loading and unloading shared
libraries in turn. One of these links againt mxml. But if mxml is unloaded
without any of its functions having been called, then the fini routine
will try to call pthread_key_delete without the key having been created.
This will thus try to delete key 0, which is likely to be used
by some other library, leading to a subsequent crash.

See the above-referenced bugzilla report for a patch that works for me.

That proposed fix leaks memory if the library has been initialized... But I can combine the two...

I'd generally suggest either

  • Always create the key in the shared library constructor, and release it in the destructor, or
  • If using pthread_once, from that function call atexit() to register a cleanup function

(On pretty much every Unix, atexit() functions will be invoked at dlclose() time, for Itanium C++ ABI related reasons)

OK, merging this issue with #294.

I've pushed the following change:

[master d32818a] Another POSIX thread destructor fix (Issue #293)

Please let me know whether this fixes the reported issue, then I'll put out a bug fix release (3.3.1).

Hi!
It looks like, that your patches fixed the issue, which also someone reported at Gentoo: https://bugs.gentoo.org/860804