Make SkRWBuffer destruct safely

Check for NULL before calling unref.

Add a test.

BUG=483369
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1691383002

Review URL: https://codereview.chromium.org/1691383002
This commit is contained in:
scroggo 2016-02-16 06:59:18 -08:00 committed by Commit bot
parent ddd22d8645
commit 9dec5d2acd
2 changed files with 10 additions and 1 deletions

View File

@ -168,7 +168,9 @@ SkRWBuffer::SkRWBuffer(size_t initialCapacity) : fHead(nullptr), fTail(nullptr),
SkRWBuffer::~SkRWBuffer() {
this->validate();
fHead->unref();
if (fHead) {
fHead->unref();
}
}
void SkRWBuffer::append(const void* src, size_t length) {

View File

@ -328,3 +328,10 @@ DEF_TEST(RWBuffer_size, r) {
REPORTER_ASSERT(r, !iter.next());
REPORTER_ASSERT(r, 0 == iter.size());
}
// Tests that it is safe to destruct an SkRWBuffer without appending
// anything to it.
DEF_TEST(RWBuffer_noAppend, r) {
SkRWBuffer buffer;
REPORTER_ASSERT(r, 0 == buffer.size());
}