Speculative fix for createBitmap crash
Bug: 112551574
Test: Infeasible
Check for a null Bitmap before attempting to dereference it.
Change-Id: I250059e87540f005017abfdd9071f2fec86c1610
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 79bfa17..70e6604 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -507,9 +507,18 @@
ninePatchChunk, ninePatchInsets, -1);
}
+ // Speculative fix for b/112551574. It doesn't seem like |b| can be null. If it is, print some
+ // info that might be helpful to diagnose.
+ Bitmap* b = defaultAllocator.getStorageObjAndReset();
+ if (!b) {
+ ALOGW("defaultAllocator has no storage object!");
+ ALOGW("\tjavaBitmap: %s", (javaBitmap == nullptr ? "null" : "present"));
+ ALOGW("\tisHardware: %s", (isHardware ? "true" : "false"));
+ ALOGW("\twillScale: %s", (willScale ? "true" : "false"));
+ return nullptr;
+ }
// now create the java bitmap
- return bitmap::createBitmap(env, defaultAllocator.getStorageObjAndReset(),
- bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1);
+ return bitmap::createBitmap(env, b, bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1);
}
static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage,