Fix crash in WindowCapturerWinGdi::CaptureFrame.

A couple crashes have been reported in Chromium due to us dereferencing
|result.frame| which can be a nullptr.

This bug tracks the addition of new test cases which will help us
avoid issues like this in the future:
https://bugs.chromium.org/p/webrtc/issues/detail?id=12682

Bug: chromium:1199257
Change-Id: I720dd6ceb38938dc392f0924acf2cac287bfcffc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215340
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Commit-Queue: Austin Orion <auorion@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#33746}
This commit is contained in:
Austin Orion 2021-04-15 09:56:07 -07:00 committed by Commit Bot
parent a80c3e5352
commit 9fea310a62

View File

@ -158,12 +158,16 @@ void WindowCapturerWinGdi::CaptureFrame() {
CaptureResults results = CaptureFrame(/*capture_owned_windows*/ true);
int capture_time_ms = (rtc::TimeNanos() - capture_start_time_nanos) /
rtc::kNumNanosecsPerMillisec;
RTC_HISTOGRAM_COUNTS_1000(
"WebRTC.DesktopCapture.Win.WindowGdiCapturerFrameTime", capture_time_ms);
results.frame->set_capture_time_ms(capture_time_ms);
results.frame->set_capturer_id(DesktopCapturerId::kWindowCapturerWinGdi);
if (results.frame) {
int capture_time_ms = (rtc::TimeNanos() - capture_start_time_nanos) /
rtc::kNumNanosecsPerMillisec;
RTC_HISTOGRAM_COUNTS_1000(
"WebRTC.DesktopCapture.Win.WindowGdiCapturerFrameTime",
capture_time_ms);
results.frame->set_capture_time_ms(capture_time_ms);
results.frame->set_capturer_id(DesktopCapturerId::kWindowCapturerWinGdi);
}
callback_->OnCaptureResult(results.result, std::move(results.frame));
}