Fix pixel ref counting bug in image decode.
Previously we called bitmap->swap while in the scope of
SkAutoLockPixels, which results in the swapped ref count
being decremented by ~SkAutoLockPixels
Change-Id: I165ab161f2db6529db2e79665981cada5ff7d54a
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index a46471b..c26c7f3 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -154,8 +154,6 @@
bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm,
SkBitmap::Config pref, Mode mode, bool reuseBitmap) {
- SkAutoLockPixels alp(*bm);
- bool hasPixels = (bm->getPixels() != NULL);
// pass a temporary bitmap, so that if we return false, we are assured of
// leaving the caller's bitmap untouched.
SkBitmap tmp;
@@ -165,16 +163,16 @@
// assign this, for use by getPrefConfig(), in case fUsePrefTable is false
fDefaultPref = pref;
- if (reuseBitmap && hasPixels) {
- if (!this->onDecode(stream, bm, mode)) {
- return false;
+ if (reuseBitmap) {
+ SkAutoLockPixels alp(*bm);
+ if (bm->getPixels() != NULL) {
+ return this->onDecode(stream, bm, mode);
}
- } else {
- if (!this->onDecode(stream, &tmp, mode)) {
- return false;
- }
- bm->swap(tmp);
}
+ if (!this->onDecode(stream, &tmp, mode)) {
+ return false;
+ }
+ bm->swap(tmp);
return true;
}