From 8226875e6c033cde5c58dd985f1bc6a1165d8e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Thu, 29 Aug 2019 15:07:47 +0200 Subject: [PATCH] Avoids race during VideoStreamEncoder unittest teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ScopedFakeClock contains a lock. Due to declaration order, this is the first member of VideoStreamEncoderTest to be destroyed. However, there are cyclic tasks that may still be running at that time, and they may try to read the time, so if we're unlucky they may trigger a use after free condition. This only affects test and is simply solved by moving the declaration to before the classes that uses it. Bug: webrtc:10929 Change-Id: I998d5ced877f355e4a45ee5cf75b2eb75faa6113 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150795 Reviewed-by: Ilya Nikolaevskiy Commit-Queue: Erik Språng Cr-Commit-Position: refs/heads/master@{#29008} --- video/video_stream_encoder_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index c0fa5dc8c6..2ed4ad9b28 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -1075,6 +1075,7 @@ class VideoStreamEncoderTest : public ::testing::Test { int codec_width_; int codec_height_; int max_framerate_; + rtc::ScopedFakeClock fake_clock_; const std::unique_ptr task_queue_factory_; TestEncoder fake_encoder_; test::VideoEncoderProxyFactory encoder_factory_; @@ -1083,7 +1084,6 @@ class VideoStreamEncoderTest : public ::testing::Test { TestSink sink_; AdaptingFrameForwarder video_source_; std::unique_ptr video_stream_encoder_; - rtc::ScopedFakeClock fake_clock_; }; TEST_F(VideoStreamEncoderTest, EncodeOneFrame) {