Skip to content

Commit

Permalink
skia: Crash when a discardable allocation fails.
Browse files Browse the repository at this point in the history
A recent change (see crbug.com/983348) made the allocation of discardable memory
return nullptr in some cases, instead of crashing. Skia is not expecting this,
triggering a nullptr dereference.

This goes back to the previous behavior (crash in case of allocation failure),
while the proper fix is to make skia expect a nullptr return value. As a
consequence, this fix is temporary until upstream skia is updated.

Bug: 1034271, 983348
Change-Id: Idc3937898e897a19ca4e6793ab4e79626fe1b319
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1968985
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#725462}
  • Loading branch information
Benoît Lizé authored and Commit Bot committed Dec 17, 2019
1 parent f290ffa commit 902e7ed
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions skia/ext/SkDiscardableMemory_chrome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <utility>

#include "base/bind_helpers.h"
#include "base/memory/discardable_memory.h"
#include "base/memory/discardable_memory_allocator.h"

Expand Down Expand Up @@ -37,7 +38,10 @@ SkDiscardableMemoryChrome::CreateMemoryAllocatorDump(
}

SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
return new SkDiscardableMemoryChrome(
base::DiscardableMemoryAllocator::GetInstance()
->AllocateLockedDiscardableMemory(bytes));
// TODO(crbug.com/1034271): Make the caller handle a nullptr return value,
// and do not die when the allocation fails.
auto discardable = base::DiscardableMemoryAllocator::GetInstance()
->AllocateLockedDiscardableMemoryWithRetryOrDie(
bytes, base::DoNothing());
return new SkDiscardableMemoryChrome(std::move(discardable));
}

0 comments on commit 902e7ed

Please sign in to comment.