Skip to content

libobs: free registered types after obs_free_data() in obs_shutdown() (#2017) - #2022

Merged
zackees merged 2 commits into
masterfrom
fix/2017-shutdown-type-lifetime
Oct 24, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/2017-shutdown-type-lifetime

Conversation

@zackees

@zackees zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member

Fixes #2017.

  • RED (first commit): new Tier 2 test test_shutdown_type_lifetime. It leaves an input of a test type and a scene in the main canvas alive, then shuts down. In local Tier 2 it fails at test_shutdown_type_lifetime.c:93 (assert_false(destroyed_after_type_freed)): the type's free_type_data ran before obs_free_data() destroyed the source. Under ASan the same order is the heap-use-after-free in obs_canvas_destroy → obs_source_is_scene (Sanitizers run 40044944211).
  • GREEN: obs_shutdown() frees the source type ids and every registered type's type_data after obs_free_data(), so no object outlives its type's registration. Local Tier 2 with the fix: 406/406 passed, including the new test. That was the first of the run's two libobs builds; PR CI runs both.

Ordering note: free_type_data now runs after the modules' obs_module_unload(), where the sources' destroys already ran. libobs never dlcloses a module (free_module), so plugin code is still mapped.

Upstream OBS has the same order. Low risk: shutdown only, reached when a host has not released its sources, and only from trusted local input. Public API only; no existing C test or public header changed. No features.md entry (no user-visible change).

…ED, #2017)

test_shutdown_type_lifetime leaves an input of a test type and a scene in
the main canvas alive and shuts down. Fails on master: the type's
free_type_data runs before obs_free_data() destroys the source
(test_shutdown_type_lifetime.c:93, local Tier 2). Under ASan the same
order is a heap-use-after-free in obs_canvas_destroy().
… (GREEN, #2017)

Sources still alive at shutdown are destroyed in obs_free_data() and read
their type's registration: obs_canvas_destroy() strcmp()s info.id through
obs_source_is_scene(), and destroy callbacks use type_data. obs_shutdown()
freed the source types' ids and every type's type_data first (ASan
heap-use-after-free in test_context_names). The type tables are now freed
after obs_free_data(); free_type_data therefore runs after the modules'
obs_module_unload(), as the sources' destroys already did (libobs never
dlcloses a module).
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Local Tier 2 with the fix, both libobs builds: test_shutdown_type_lifetime passes in both. The first build passed 406/406. The second had one failure, test_async_delay_audio:466 (real-time audio lost under load). That test also failed on the RED branch before the fix, and it passed in the first build; added to the flaky-audio issue #838.

@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into master with commit 46a482f Oct 24, 2026
31 checks passed
@zackees
zackees deleted the fix/2017-shutdown-type-lifetime branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: obs_shutdown frees source type ids before canvases release their scenes (heap-use-after-free)

1 participant