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}
diff --git a/modules/desktop_capture/desktop_frame_win.cc b/modules/desktop_capture/desktop_frame_win.cc
index 58ebac9..262ebbd 100644
--- a/modules/desktop_capture/desktop_frame_win.cc
+++ b/modules/desktop_capture/desktop_frame_win.cc
@@ -50,6 +50,10 @@
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;