Fix potential UAF in unit test.

In WebRtcVideoChannelBaseTest.EncoderSelectorSwitchCodec a mock encoder
selecter or stack allocated and then registered with the channel.
Since this test uses real-time clocks/threads, there is a chance that
the selector callback will be called after the mock goes out of scope,
but before the test had time to be torn down.

This CL fixes that by simply de-registering the callback before the
end of the test.

Bug: b/239855550
Change-Id: Ibb38a914933494fd04c963b9a13f2cc4aee160d6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269402
Auto-Submit: Erik Språng <sprang@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37618}
This commit is contained in:
Erik Språng 2022-07-26 10:30:49 +02:00 committed by WebRTC LUCI CQ
parent 5793ed8ff9
commit a3f2e72008

View File

@ -9036,6 +9036,9 @@ TEST_F(WebRtcVideoChannelBaseTest, EncoderSelectorSwitchCodec) {
ASSERT_TRUE(channel_->GetSendCodec(&codec));
EXPECT_EQ("VP9", codec.name);
// Deregister the encoder selector in case it's called during test tear-down.
channel_->SetEncoderSelector(kSsrc, nullptr);
}
} // namespace cricket