From 1eebec980898ad142d3b2e5d172c27aaf365aaa4 Mon Sep 17 00:00:00 2001 From: "Piotr (Peter) Slatala" Date: Fri, 16 Nov 2018 09:03:35 -0800 Subject: [PATCH] Fix data race in channel_send.cc 'configured_bitrate_bps_' is accessed from different threads in SetBitrate and GetBitrate (one comes back from OnNetworkRouteChange callback, the other one is used in GetStats()) and so it should be protected by a critical section. Bug: webrtc:10010 Change-Id: I029baa729e0203b9f2d180d8835d61add26e6cef Reviewed-on: https://webrtc-review.googlesource.com/c/111281 Commit-Queue: Peter Slatala Reviewed-by: Fredrik Solenberg Cr-Commit-Position: refs/heads/master@{#25675} --- audio/channel_send.cc | 2 ++ audio/channel_send.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/audio/channel_send.cc b/audio/channel_send.cc index abdb9807d9..a8b93ccd2a 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -641,6 +641,7 @@ void ChannelSend::ModifyEncoder( } void ChannelSend::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) { + rtc::CritScope lock(&bitrate_crit_section_); audio_coding_->ModifyEncoder([&](std::unique_ptr* encoder) { if (*encoder) { (*encoder)->OnReceivedUplinkBandwidth(bitrate_bps, probing_interval_ms); @@ -651,6 +652,7 @@ void ChannelSend::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) { } int ChannelSend::GetBitRate() const { + rtc::CritScope lock(&bitrate_crit_section_); return configured_bitrate_bps_; } diff --git a/audio/channel_send.h b/audio/channel_send.h index 6fefd281d0..63e8d04e86 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -324,7 +324,9 @@ class ChannelSend rtc::scoped_refptr frame_encryptor_; // E2EE Frame Encryption Options webrtc::CryptoOptions crypto_options_; - int configured_bitrate_bps_ = 0; + + rtc::CriticalSection bitrate_crit_section_; + int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_crit_section_) = 0; }; } // namespace voe