From 0529791ef794e7511334cf3327bcec9fb6ed2613 Mon Sep 17 00:00:00 2001 From: Joe Downing Date: Tue, 21 Sep 2021 13:08:12 -0700 Subject: [PATCH] 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 Commit-Queue: Joe Downing Cr-Commit-Position: refs/heads/main@{#35072} --- modules/desktop_capture/desktop_frame_win.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/desktop_capture/desktop_frame_win.cc b/modules/desktop_capture/desktop_frame_win.cc index 58ebac91d5..262ebbdec0 100644 --- a/modules/desktop_capture/desktop_frame_win.cc +++ b/modules/desktop_capture/desktop_frame_win.cc @@ -50,6 +50,10 @@ std::unique_ptr 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;