Release resources if SkMallocPixelRef::NewWithProc fails.
Change-Id: I29b96cd9f2d2311b4caae092102f501dbc6a4fe8
Reviewed-on: https://skia-review.googlesource.com/9182
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/tests/MallocPixelRefTest.cpp b/tests/MallocPixelRefTest.cpp
index 7e2bece..b89d121 100644
--- a/tests/MallocPixelRefTest.cpp
+++ b/tests/MallocPixelRefTest.cpp
@@ -86,6 +86,17 @@
REPORTER_ASSERT(reporter, 1 == x);
}
{
+ int x = 0;
+ SkAutoMalloc memory(size);
+ sk_sp<SkMallocPixelRef> pr(
+ SkMallocPixelRef::NewWithProc(SkImageInfo::MakeN32Premul(-1, -1), rowBytes, nullptr,
+ memory.get(), set_to_one_proc,
+ static_cast<void*>(&x)));
+ REPORTER_ASSERT(reporter, pr.get() == nullptr);
+ // make sure that set_to_one_proc was called.
+ REPORTER_ASSERT(reporter, 1 == x);
+ }
+ {
void* addr = static_cast<void*>(new uint8_t[size]);
REPORTER_ASSERT(reporter, addr != nullptr);
sk_sp<SkMallocPixelRef> pr(