summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2013-12-04 17:32:43 -0800
committerMathieu Chartier <mathieuc@google.com>2013-12-04 17:58:37 -0800
commita1a19d28d0e432c2d90e4fd73146891c57d01479 (patch)
tree04da997477d4e57e5ef610526fbbb6361f092efa /core
parent453a5233086b216f2a95d0879954a2af39279095 (diff)
downloadframeworks_base-a1a19d28d0e432c2d90e4fd73146891c57d01479.zip
frameworks_base-a1a19d28d0e432c2d90e4fd73146891c57d01479.tar.gz
frameworks_base-a1a19d28d0e432c2d90e4fd73146891c57d01479.tar.bz2
Use exceptionCheck after VMRuntime.newNonMovableArray/addressOf.
Since VMRuntime.newNonMovableArray and VMRuntime.addressOf are java methods implemented in Native, they don't necessarily return NULL when an exception is thrown. Checking the exception instead of the return value fixes errors which may occur if the runtime returns garbage when an exception is pending. Bug: 11971220 Change-Id: I70478834c9f14cc5d9e666e1e174d3fd09269719
Diffstat (limited to 'core')
-rw-r--r--core/jni/android/graphics/Graphics.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 0a8eeab..38a9ba3 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -547,16 +547,20 @@ jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
gVMRuntime_newNonMovableArray,
gByte_class, size);
- if (arrayObj) {
- jbyte* addr = (jbyte*) env->CallLongMethod(gVMRuntime, gVMRuntime_addressOf, arrayObj);
- if (addr) {
- SkPixelRef* pr = new AndroidPixelRef(env, (void*) addr, size, arrayObj, ctable);
- bitmap->setPixelRef(pr)->unref();
- // since we're already allocated, we lockPixels right away
- // HeapAllocator behaves this way too
- bitmap->lockPixels();
- }
+ if (env->ExceptionCheck() != 0) {
+ return NULL;
+ }
+ SkASSERT(arrayObj);
+ jbyte* addr = (jbyte*) env->CallLongMethod(gVMRuntime, gVMRuntime_addressOf, arrayObj);
+ if (env->ExceptionCheck() != 0) {
+ return NULL;
}
+ SkASSERT(addr);
+ SkPixelRef* pr = new AndroidPixelRef(env, (void*) addr, size, arrayObj, ctable);
+ bitmap->setPixelRef(pr)->unref();
+ // since we're already allocated, we lockPixels right away
+ // HeapAllocator behaves this way too
+ bitmap->lockPixels();
return arrayObj;
}