Handle SharedMemory allocation failures

CreateSharedMemory is allowed to return nullptr if memory can't be
allocated but DesktopFrameWin didn't check to ensure was allocated
before accessing it. This CL just adds a null check, logs a
warning, and returns nullptr which is already done lower in the
function and the error is correctly handled in the screen and window
capturers which call DesktopFrameWin::Create().

Bug: chromium:1251651
Change-Id: Ie9231f03ba9c7a96823af986b9df38f97fcb682c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232663
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#35072}
This commit is contained in:
Joe Downing 2021-09-21 13:08:12 -07:00 committed by WebRTC LUCI CQ
parent 98952d7f0f
commit 0529791ef7

View file

@ -50,6 +50,10 @@ std::unique_ptr<DesktopFrameWin> DesktopFrameWin::Create(
HANDLE section_handle = nullptr;
if (shared_memory_factory) {
shared_memory = shared_memory_factory->CreateSharedMemory(buffer_size);
if (!shared_memory) {
RTC_LOG(LS_WARNING) << "Failed to allocate shared memory";
return nullptr;
}
section_handle = shared_memory->handle();
}
void* data = nullptr;