Skip to content

Never destroy class_loader's global state - #245

Draft
mjcarroll wants to merge 1 commit into
mjcarroll/multi-loader-ownershipfrom
mjcarroll/never-destroyed-globals
Draft

mjcarroll wants to merge 1 commit into
mjcarroll/multi-loader-ownershipfrom
mjcarroll/never-destroyed-globals

Conversation

@mjcarroll

@mjcarroll mjcarroll commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #33.

A ClassLoader with static storage duration (e.g. a static pluginlib::ClassLoader) is usually destroyed after class_loader's function-local statics, so its destructor uses the already-destroyed library vector, factory maps and mutexes. The globals in class_loader_core.cpp are now allocated on first use and never destroyed, which also makes the MetaObjectGraveyardVector destructor workaround unnecessary.

Is this user-facing behavior change?

No.

Did you use Generative AI?

Claude Code (Claude Opus 5.5) wrote the change; I reviewed it.

Additional Information

Stacked on #244, the other half of #33; I'll retarget this to rolling once that merges. New death test ClassLoaderStaticTest.staticLoadersDestroyedAtExit fails under ASan without the fix.

A ClassLoader or MultiLibraryClassLoader with static storage duration,
such as a static pluginlib::ClassLoader, is usually created before
class_loader's function-local static globals, so it is destroyed after
them at exit. Its destructor then unloads its libraries using the
already-destroyed library vector, factory maps and mutexes.

Allocate the globals on first use and never destroy them. This also
makes the MetaObjectGraveyardVector destructor workaround unnecessary.

Fixes #33

Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
@mjcarroll mjcarroll self-assigned this Nov 10, 2026
@mjcarroll
mjcarroll marked this pull request as draft November 10, 2026 03:29
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.

1 participant