Skip to content

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

Closed

Description

@zackees

Problem

ASan reports a heap-use-after-free in test_context_names at shutdown (Sanitizers asan run 40044944211, artifact sanitize-asan, tests/test_context_names.asan.*):

READ of size 6 ... in strcmp
  #1 obs_source_is_scene        libobs/obs-scene.c.h:3796
  #2 obs_canvas_destroy         libobs/obs-canvas.c.h:213
  #3 obs_canvas_release         libobs/obs-canvas.c.h:83
  #5 obs_free_data              libobs/obs.c.h:817
  #6 obs_shutdown               libobs/obs.c.h:1253
freed by: obs_shutdown          libobs/obs.c.h:1209   (bfree(item->id) of obs->source_types)
allocated by: obs_init          libobs/obs.c.h:1072   (obs_register_source(&scene_info))

obs_shutdown() frees every registered source type's id (and calls free_type_data) before obs_free_data() releases the canvases. obs_canvas_destroy() then calls obs_source_is_scene() on each source still in a SCENE_REF canvas, and that strcmps source->info.id, a pointer into the freed registration. Any source destroyed in obs_free_data() reads its type's info after the type is gone.

Upstream OBS has the same order. Low risk: only reached at shutdown with sources still alive (a host that doesn't release its scenes first). Only trusted local input reaches it.

Fix sketch

Free the registered type tables (source_types ids and type_data, and the output, encoder and service type_data) after obs_free_data(), so no object outlives its type's registration. Test: a cmocka test that leaves a scene in the main canvas at obs_shutdown() and checks that the scene's type is still readable while it is destroyed (for example, its destroy callback reads obs_source_get_id). Tier 2 against the C reference and the hybrid libobs.

Activity

  1. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Claiming: #2017.

    Plan (one PR): a RED Tier 2 cmocka test, a scene left in the main canvas at obs_shutdown() whose destroy path reads its type id, first against the C reference; then GREEN: free the registered type tables after obs_free_data(). PR today.

  2. added
    claimed
    on Oct 24, 2026
  3. zackees commented on Oct 24, 2026

    @zackees
    MemberAuthor

    Fixed by #2022 (merged). obs_shutdown now frees the registered source types after obs_free_data. The new test, test_shutdown_type_lifetime, covers it. Nothing left to do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions