You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Activity
mac-capture: Wait for SCK stop and fence callbacks before free
mac-capture: Factor SCK stop wait and free decision for cmocka
mac-capture: Leak SCK capture when stop completion never fires
test: Fail the SCK stop wait against a stub (RED)
mac-capture: Wait for SCK stop and fence callbacks before free (GREEN)