浏览代码

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.
Ben Wiederhake 4 年之前
父节点
当前提交
ecb16f421d
共有 1 个文件被更改,包括 2 次插入0 次删除
  1. 2 0
      Libraries/LibGfx/Bitmap.cpp

+ 2 - 0
Libraries/LibGfx/Bitmap.cpp

@@ -345,6 +345,8 @@ RefPtr<Bitmap> Bitmap::to_bitmap_backed_by_shared_buffer() const
     if (m_shared_buffer)
     if (m_shared_buffer)
         return *this;
         return *this;
     auto buffer = SharedBuffer::create_with_size(size_in_bytes());
     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());
     auto bitmap = Bitmap::create_with_shared_buffer(m_format, *buffer, m_size, palette_to_vector());
     if (!bitmap)
     if (!bitmap)
         return nullptr;
         return nullptr;