Wayland screencast: fix data race in CaptureFrame() CaptureFrame() was reading pw_stream_ without holding any lock, which races with StopAndCleanupStream() and StartScreenCastStream() accessing it from other threads. Remove the unguarded pw_stream_ check and rely solely on latest_available_frame_, which is already protected by latest_frame_lock_. Bug: webrtc:42223634 Change-Id: I8e1df44f4ec971948411be45cdf4140b2dcfc553 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/453020 Reviewed-by: Mark Foltz <mfoltz@chromium.org> Reviewed-by: Andreas Pehrson <apehrson@mozilla.com> Reviewed-by: Alexander Cooper <alcooper@chromium.org> Commit-Queue: Mark Foltz <mfoltz@chromium.org> Cr-Commit-Position: refs/heads/main@{#47092}
diff --git a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc index 44eab8f..d611ca0 100644 --- a/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc +++ b/modules/desktop_capture/linux/wayland/shared_screencast_stream.cc
@@ -654,13 +654,13 @@ pw_stream_ = nullptr; { - MutexLock lock(&queue_lock_); - queue_.Reset(); - } - { MutexLock latest_frame_lock(&latest_frame_lock_); latest_available_frame_ = nullptr; } + { + MutexLock lock(&queue_lock_); + queue_.Reset(); + } } if (pw_core_) { @@ -681,7 +681,7 @@ SharedScreenCastStreamPrivate::CaptureFrame() { MutexLock latest_frame_lock(&latest_frame_lock_); - if (!pw_stream_ || !latest_available_frame_) { + if (!latest_available_frame_) { return std::unique_ptr<SharedDesktopFrame>{}; }