Skip to content

fix(libobs): only destroy the audio mutexes obs_init_audio created (#2910) - #2911

Merged
zackees merged 2 commits into
masterfrom
fix/2910-free-audio-cold-core
Oct 29, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/2910-free-audio-cold-core

Conversation

@zackees

@zackees zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

Fixes #2910.

What changed

obs_free_audio() destroyed task_mutex and monitoring_mutex unconditionally, but only obs_init_audio() creates them. obs_reset_audio2(NULL) frees before it looks at the info (libobs/obs.c.h:1621), so a reset on a core that was never opened destroyed zeroed memory.

  • struct obs_core_audio gains mutexes_initialised (libobs/obs-internal.h), set by obs_init_audio() only after both mutexes exist.
  • obs_free_audio() destroys them only when that flag is set; it also clears the flag via the existing memset, so a later open re-arms it.
  • obs_init_audio() now destroys the monitoring mutex when the task mutex fails to initialise, instead of leaking it.

No behaviour change for a normal open/close: both mutexes are created and destroyed exactly as before whenever audio was opened.

RED — the Windows Tier 2 lane, job 123456184550

There is no Linux-side RED for this: glibc makes pthread_mutex_destroy on a zeroed mutex a no-op, so Rust Tier 2 Linux 🐧 (tests ON) passes on master. The failure only exists on the Windows pthread layer, which is the lane #2881's own PR skipped:

142/327 Test #145: test_core_setup_rules_steps ....................***Failed    0.04 sec
[==========] callers: Running 7 test(s).
[       OK ] test_reset_video_gates
[  ERROR   ] --- Test failed with exception: (11)
[  FAILED  ] test_reset_audio_ticks
...
[  ERROR   ] --- Test failed with exception: (11)
[  FAILED  ] GROUP TEARDOWN
 2 FAILED TEST(S)

The first statement of test_reset_audio_ticks is assert_true(obs_reset_audio2(NULL)), and every test that passes in that group is one that never calls obs_reset_audio2(). The job is Build 🧱 / Rust Tier 2 (windows-2025-vs2026) in run 40875411169, on a PR whose libobs/ and test/cmocka/test_core_setup_rules_steps.c are identical to master (git diff origin/master <head> -- libobs test/cmocka/test_core_setup_rules_steps.c is empty).

Commit eb56094bc (test(core): pin a reset with no info on a never-opened audio core) adds test_reset_audio_cold as the first case of the callers group: a null reset twice on the cold core, then a real reset that must succeed, then a cold reset again. It passes on Linux before and after the fix — it pins the behaviour the fix has to keep (the crash must not be "fixed" by rejecting the null reset), not a Linux-visible regression.

GREEN — 56853180c

ninja -C build libobs builds clean; ./lint --fix is ok (47.2 s). The Windows lane on this PR is the GREEN evidence and is what I am watching; this PR is a draft until it is green.

No docs/features.md line: internal lifetime fix, nothing user-visible.

)

The Windows Tier 2 lane segfaults in this group: obs_reset_audio2(NULL) reaches obs_free_audio() before obs_init_audio() ever ran, and it destroys two mutexes that were never initialised. glibc tolerates that; the Windows pthread layer does not, so the failure is only visible in the Windows job cited on the issue.

This case pins the behaviour the fix must keep: the null reset is a success on a cold core, twice, then a real reset works and the cold reset succeeds again.
…2910)

obs_free_audio() ran pthread_mutex_destroy on a core that was never opened, so obs_reset_audio2(NULL) before the first successful obs_reset_audio2(info) destroyed zeroed memory. Linux's glibc makes that a no-op; on Windows it faulted and took the whole cmocka group down (build(cmake) lane job 123456184550).

obs_init_audio() now records that both mutexes exist, and obs_free_audio() destroys them only then. It also destroys the monitoring mutex if the task mutex fails to initialise, instead of leaking it. A real open still frees both in obs_shutdown.
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

The PR's own CI does not select the lane this fixes: ci/ci_scope.py treats libobs/ as core (Linux Tier 2 only), so Build 🧱 / Rust Tier 2 (windows-2025-vs2026) is skipped on this PR (check-event.outputs.windows != 'true'). That is the same scope rule that let #2881 reach master: its PR run skipped both Windows jobs, and master pushes skip the lane too, so the first real exercise of this test on Windows was an unrelated PR that touched shared/.

Evidence run: gh workflow run scheduled.yaml --ref fix/2910-free-audio-cold-core → run 40879828636. workflow_dispatch sets event_full=true, so windows=true and the Windows Tier 2 lane runs this branch. I am watching that job; this PR stays a draft until it is green, and the result goes here.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

GREEN on the lane that fails. The workflow_dispatch run on this exact head (56853180c) produced the Windows lane the PR run skips:

  • run 40879828636 — Build 🧱 / Rust Tier 2 (windows-2025-vs2026): success.
  • Build 🧱 / Rust Tier 2 Linux 🐧 (tests ON) and (tests OFF): success, so the Linux side is unchanged.

That is the same job that fails on master in test_core_setup_rules_steps (test_reset_audio_ticks, test_monitoring_device, GROUP TEARDOWN, exception 11) — see #2912 for the master-side record. With the mutex flag in place the group passes on both Windows and Linux.

Marking ready and queueing.

@zackees
zackees marked this pull request as ready for review October 29, 2026 13:36
@zackees
zackees added this pull request to the merge queue Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Windows Tier 2 is green on this branch.

Run 40879828636 (workflow_dispatch of scheduled.yaml on fix/2910-free-audio-cold-core, event_full=true → windows=true), job 123474622500:

143/327 Test #145: test_core_setup_rules_steps ....................   Passed    0.15 sec
100% tests passed out of 327

It passed in all four native-core passes of the job (327/327 each), and the new test_reset_audio_cold case is in that binary. The same test binary segfaulted in the same lane on master's code before the fix (job 123456184550, quoted above), so this is the RED → GREEN pair for a Windows-only failure.

Also green on the PR itself: Rust Tier 2 Linux 🐧 (tests ON) and its serial shards, Fast Gate ⚡, Format 🔍 / checks, CI Mode 🛂, Validate Data 🕵️.

Handed off to the coordinator — it is in the merge queue (position 1, AWAITING_CHECKS).

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: test_core_setup_rules_steps segfaults in the Windows Tier 2 lane, so master's Windows gate is red (#2881)

1 participant