make SkAutoTMalloc self-move safe
We were just combing through possible changes that might have affected the attached bug, this popped out as pretty obviously unsafe. This doesn't explain the Chrome bug... SkAutoTMalloc and SKAutoSTMalloc are separate types. :( The new test fails and crashes before, passes after. Change-Id: I033f488a7f644b7a70e612c8535fedfac35c76db Reviewed-on: https://skia-review.googlesource.com/11797 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
parent
266dcb0599
commit
149e42ed19
@ -294,8 +294,10 @@ public:
|
||||
}
|
||||
|
||||
SkAutoTMalloc& operator=(SkAutoTMalloc<T>&& that) {
|
||||
sk_free(fPtr);
|
||||
fPtr = that.release();
|
||||
if (this != &that) {
|
||||
sk_free(fPtr);
|
||||
fPtr = that.release();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -126,3 +126,20 @@ DEF_TEST(AutoReallocToZero, reporter) {
|
||||
test_realloc_to_zero<SkAutoTMalloc<int> >(reporter);
|
||||
test_realloc_to_zero<SkAutoSTMalloc<kStackPreallocCount, int> >(reporter);
|
||||
}
|
||||
|
||||
DEF_TEST(SkAutoTMallocSelfMove, r) {
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wself-move"
|
||||
#endif
|
||||
|
||||
SkAutoTMalloc<int> foo(20);
|
||||
REPORTER_ASSERT(r, foo.get());
|
||||
|
||||
foo = std::move(foo);
|
||||
REPORTER_ASSERT(r, foo.get());
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user