Skip to content

fix(canvas): release a source's weak canvas ref after the canvas is gone - #2041

Merged
zackees merged 3 commits into
masterfrom
fix/canvas-weak-ref-shutdown-leak
Oct 24, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/canvas-weak-ref-shutdown-leak

Conversation

@zackees

@zackees zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member

Fixes #2038

obs_free_data() releases the main canvas before it destroys the sources the host left alive. obs_canvas_remove_source() released source->canvas only while the canvas was still alive, so each leftover source leaked its weak ref, and the canvas control block leaked with it (ASan: obs-canvas.c.h:330 and :158 in test_context_names and test_shutdown_type_lifetime).

  • RED (first commit): the new test_shutdown_canvas_weak_ref (Tier 2, public API) checks bnum_allocs() after shutting down with a source and a scene left alive. Local ./unittest fails with 5 != 0 at line 68, and every other test in that run passes (411/412).
  • GREEN: release the weak ref whether or not obs_weak_canvas_get_canvas still returns the canvas. obs_weak_canvas_release is safe on NULL. ./lint passes; PR CI runs Tier 2 against both libobs builds.

Tiers 1 and 3 don't apply: obs-canvas has no Rust port yet.

@zackees
zackees enabled auto-merge October 24, 2026 03:26
…urces left in it (#2038)

The test now expects only the two leftover sources' control blocks after
shutdown: obs_free_data() leaves those by design.
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Pushed f8af0de. With the full ASan stacks from #2036, the 5 leaked allocations are: the canvas control block (fixed by 7e932c9), the canvas's source-name hash table and its bucket array (obs_canvas_destroy never freed them while sources were left in it; fixed now with HASH_CLEAR), and one control block for each of the 2 leftover sources. Those two stay by design: obs_free_data() destroys a leftover source without freeing the control block the host's reference points to. The test now expects bnum_allocs() - before == 2. RED still holds: the unfixed code leaves 5.

@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into master with commit 08aed4e Oct 24, 2026
31 checks passed
@zackees

zackees commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@zackees master regression, probably from this PR: test_context_names / test_canvas_sources now segfaults intermittently in Tier 2 Linux:

[ RUN      ] test_canvas_sources
Test failed with exception: Segmentation fault(11)
Test teardown failed

It first fails on master at 08aed4e (this PR). Since then it failed in master runs 40060359610 and 40060836905 and in the merge groups for #2046 (40065324798) and #2054, while other runs pass. The test creates and releases sources on canvases, which is the weak-canvas-ref path changed here. It is ejecting unrelated PRs from the queue.

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.

obs_shutdown leaks the weak canvas refs of sources left alive

1 participant