Repository navigation
fix(canvas): don't read a scene after releasing the canvas's last ref to it (#2049) - #2052
Merged
Merged
Conversation
HASH_CLEAR read the table through the list head after the loop had released it; the destruction task thread could have freed that scene.
Member
Author
|
The hh.next fix alone did not stop the crash (run 40065512336 still segfaulted in test_context_names teardown). Second use after free in the same function: HASH_CLEAR (added in #2041) reads |
zackees
force-pushed
the
fix/2049-canvas-teardown
branch
from
October 24, 2026 05:40
35164f4 to
a8fe884
Compare
zackees
marked this pull request as ready for review
October 24, 2026 05:50
This was referenced Oct 24, 2026
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2049
Cause
obs_canvas_destroy()walks its source list and releases the reference a SCENE_REF canvas holds on each scene. It readsource->context.hh.nextafterobs_source_release(source). When that was the last reference,obs_source_destroy()queued the scene's free onobs->destruction_task_thread(obs_source_destroy_defer). The walk's read then raced that free on another thread. It loses only rarely, which is whytest_context_names(test_canvas_sources, during teardown) crashed only now and then.Fix
Take
hh.nextbefore the release. A destroyed scene stays in the list: with the canvas at zero references,obs_canvas_remove_source()cannot find the canvas to unlink it. So the saved next pointer stays valid. Releasing one scene never frees another one in this canvas, because each scene still holds the canvas's own reference until its turn. TheHASH_CLEARthat #2041 added frees only the table.Test, and why RED is not deterministic
test/cmocka/test_canvas_destroy_scene_refs.c(public API, Linux, under xvfb liketest_shutdown_canvas_weak_ref):SCENE_REF | EPHEMERALcanvases, each holding the last reference to 16 scenes;mallopt(M_PERTURB), so a lost race follows a garbage pointer.Because the free runs on the destruction thread, no public API makes the race deterministic. The first RED commit (4 scenes) passed in CI run 40063990812. The recorded failure is #2049's crash in run 40061416995:
test_context_names→test_canvas_sources→Segmentation fault(11)Test teardown failed. The stress test now runs the race 1,600 times per run, so a regression is more likely to show up, but it is not guaranteed to.Tiers: Tier 2 (libobs, the hybrid and libobs-c-reference). No Rust or public header change.