diff options
| author | 2010-05-06 16:06:48 -0700 | |
|---|---|---|
| committer | 2010-05-06 16:35:21 -0700 | |
| commit | 485dd21bbefde378c392da3de48887aee9fabebe (patch) | |
| tree | 5ca10e140988dde25261989d3d2c58e04a906193 | |
| parent | 9d164dc5c1be55287725343349923f705a5bf8d4 (diff) | |
Prevent local reference table overflows
If we're grabbing references to many strings in a loop, we have to
remove our local references so we don't overflow the VM's local
reference table.
Also, use env->ExceptionCheck() instead of checking for NULL value
returns on trying to allocate new items.
Bug: 2663816
Change-Id: I9cb5e17f6181dbb2f2c03d53841b2f5d8ab10f68
| -rw-r--r-- | core/jni/android_util_AssetManager.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index a2b7cc4d1104..b7d0c67d7555 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -1504,8 +1504,7 @@ static jobjectArray android_content_AssetManager_getArrayStringResource(JNIEnv* } jobjectArray array = env->NewObjectArray(N, cls, NULL); - if (array == NULL) { - doThrow(env, "java/lang/OutOfMemoryError"); + if (env->ExceptionCheck()) { res.unlockBag(startOfBag); return NULL; } @@ -1533,15 +1532,23 @@ static jobjectArray android_content_AssetManager_getArrayStringResource(JNIEnv* } else { const char16_t* str16 = pool->stringAt(value.data, &strLen); str = env->NewString(str16, strLen); - if (str == NULL) { - doThrow(env, "java/lang/OutOfMemoryError"); - res.unlockBag(startOfBag); - return NULL; - } + } + + // If one of our NewString{UTF} calls failed due to memory, an + // exception will be pending. + if (env->ExceptionCheck()) { + res.unlockBag(startOfBag); + return NULL; } } env->SetObjectArrayElement(array, i, str); + + // If we have a large amount of strings in our array, we might + // overflow the local reference table of the VM. + if (str != NULL) { + env->DeleteLocalRef(str); + } } res.unlockBag(startOfBag); return array; |