Skip to content

[crash] mac-capture SCK: delegate callbacks dereference freed screen_capture on teardown #93

Closed
chriscoveries/obsrust-fork
#11

Description

@chriscoveries

Class: use-after-free / teardown race, reachable from user actions while a capture device stream is live.

destroy_screen_stream (plugins/mac-capture/mac-sck-video-capture.m:4-13) calls the asynchronous [sc->disp stopCaptureWithCompletionHandler:...] and proceeds immediately; sck_video_capture_destroy (:45-72) releases sc->capture_delegate and calls bfree(sc) — without draining ScreenCaptureKit's sample-handler queue. The audio variant has the same shape (plugins/mac-capture/mac-sck-audio-capture.m:8-16, destroy at :32-54).

ScreenCaptureDelegate keeps a raw struct screen_capture *sc (self.sc), assigned at mac-sck-video-capture.m:189-190 / mac-sck-audio-capture.m:189-190. In-flight stream:didOutputSampleBuffer:ofType: on SCK's queue dereferences it (plugins/mac-capture/mac-sck-common.m:16-27 → screen_stream_video_update → pthread_mutex_lock(&sc->mutex) at :266 on a destroyed mutex), and stream:didStopWithError: writes self.sc->capture_failed = true and calls obs_source_update_properties(self.sc->source) (:47-48) — a write-after-free plus a call on a freed source path.

Trigger: remove a display/window/audio capture source, or change its type, while the SCStream is delivering frames — a normal user action, also driven by the scene switcher. The stop completion handler is fire-and-forget, so the race window is real.

Fix sketch: sc->capture_delegate.sc = NULL and removeStreamOutput:type:error: before releasing the stream, and/or wait on a semaphore for stopCaptureWithCompletionHandler before bfree(sc).

— RD1

Activity

  1. added 3 commits that reference this issue on Oct 10, 2026
    846ce24
    2059e5f
    545ae99
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions