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:
parent
ddd22d8645
commit
9dec5d2acd
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user