From ecb16f421d53cd8ebee301d25458fe192fe99689 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 5 Dec 2020 20:43:19 +0100 Subject: [PATCH] LibGfx: Handle OOM slightly better When create_with_shared_buffer() is called in the next line, the RefPtr::operator* asserts that the RefPtr is not null. That can happen when we're low-ish on memory, and the image is huge. --- Libraries/LibGfx/Bitmap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Libraries/LibGfx/Bitmap.cpp b/Libraries/LibGfx/Bitmap.cpp index cc102d45c01..259077d5a7d 100644 --- a/Libraries/LibGfx/Bitmap.cpp +++ b/Libraries/LibGfx/Bitmap.cpp @@ -345,6 +345,8 @@ RefPtr Bitmap::to_bitmap_backed_by_shared_buffer() const if (m_shared_buffer) return *this; auto buffer = SharedBuffer::create_with_size(size_in_bytes()); + if (!buffer) + return nullptr; auto bitmap = Bitmap::create_with_shared_buffer(m_format, *buffer, m_size, palette_to_vector()); if (!bitmap) return nullptr;