Skip to content

bug: libobs: a failed PulseAudio monitor reset frees the live monitor and leaves dangling state (Linux) #486

Closed

Description

@chriscoveries

Summary

On Linux with PulseAudio, audio_monitor_reset tears down the working monitor before it knows the replacement can be created. If creating the replacement fails (server restart, sink missing, sink query error), monitoring silently stops and the monitor is left holding a freed resampler and device string, still registered with the audio system. Destroying it later frees them again and releases the PulseAudio wrapper reference a second time. Severity: medium. It needs a failed reset, but the result is lost monitoring plus a crash or heap corruption on the next destroy.

Steps / trigger

  1. On Linux with PulseAudio, enable audio monitoring on a source.
  2. Trigger a reset while creating the replacement will fail: call obs_reset_audio_monitoring(), or remove the sink so a sink event triggers one, at a moment when the server query or the new playback connection fails.
  3. Monitoring stops. Disabling monitoring on the source, or shutting down, then destroys the monitor with dangling pointers.

Cause

Line numbers are against current master.

  • libobs/audio-monitoring/pulse/pulseaudio-output.c:598: audio_monitor_reset calls audio_monitor_free(monitor) first.
  • :554-570: audio_monitor_free removes the capture callback, destroys the resampler (:562), stops the stream (:565-566), drops a wrapper reference (:567) and frees device (:569). It does not clear resampler or device.
  • :601, :604-609: the new monitor is built after that. If audio_monitor_init fails, the old monitor is left as freed and nothing replaces it.
  • :612-615: audio_monitor_destroy runs audio_monitor_free on the same monitor again. That destroys the resampler and frees device a second time and calls pulseaudio_unref() again.
  • libobs/obs.c:2997 (obs_reset_audio_monitoring) and pulseaudio-output.c:499-500 (sink events) are the callers that reach the reset.

The backend has no Rust counterpart, so ON and OFF behave the same.

Proposed fix

Create the replacement monitor before releasing the old one: on success release the old monitor and publish the new one, on failure keep the working old monitor (resampler, stream and capture callback) untouched. Also retire and recreate a PulseAudio context that has gone failed or terminated when the wrapper is initialised, otherwise a replacement cannot succeed while other monitors still hold wrapper references. If the old stream has already detached when the replacement fails, release it fully and leave an empty, ignored monitor that is safe to retry or destroy. The regression test replaces the libpulse calls and covers a healthy-context failure, failed and terminated contexts, two monitors sharing a failed context, and a terminal context with a failed replacement.

I'd like to work on this; a fix with a regression test is ready.

Activity

  1. zackees commented on Oct 13, 2026

    @zackees
    Member

    @chriscoveries go ahead: please open the PR with the RED test commit first, then the fix (one PR per issue, targeting master). Marking it claimed for you so nobody duplicates it.

  2. added
    claimed
    on Oct 13, 2026
  3. chriscoveries commented on Oct 14, 2026

    @chriscoveries
    ContributorAuthor

    Releasing this one. We're backed up on CI and won't get it landed soon, so anyone who wants it is welcome to take it.

    If it helps, our RED test and fix are on the fork branch fix/pulse-monitor-reset-failure. They passed review on our side but haven't been through CI, so reuse them or start fresh, whichever you prefer.

  4. zackees commented on Oct 14, 2026

    @zackees
    Member

    Claiming.

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