diff options
author | Alyssa Milburn | 2013-05-16 12:55:06 +0200 |
---|---|---|
committer | Alyssa Milburn | 2013-05-16 12:55:06 +0200 |
commit | 89d9a624d9f0b4f5ba07259d5f90f7f85f15a0df (patch) | |
tree | b354346e4782ecf1e856d9bb3badb980d47fe2af /backends/platform | |
parent | 2743da58542aceb21d2403bdcbd8305a3a1ab52e (diff) | |
download | scummvm-rg350-89d9a624d9f0b4f5ba07259d5f90f7f85f15a0df.tar.gz scummvm-rg350-89d9a624d9f0b4f5ba07259d5f90f7f85f15a0df.tar.bz2 scummvm-rg350-89d9a624d9f0b4f5ba07259d5f90f7f85f15a0df.zip |
ANDROID: Delete local JNI references to asset data/classes.
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/android/asset-archive.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/backends/platform/android/asset-archive.cpp b/backends/platform/android/asset-archive.cpp index 14840de996..f1decfb7fa 100644 --- a/backends/platform/android/asset-archive.cpp +++ b/backends/platform/android/asset-archive.cpp @@ -97,7 +97,9 @@ JavaInputStream::JavaInputStream(JNIEnv *env, jobject is) : { _input_stream = env->NewGlobalRef(is); _buflen = 8192; - _buf = (jbyteArray)env->NewGlobalRef(env->NewByteArray(_buflen)); + jobject buf = env->NewByteArray(_buflen); + _buf = (jbyteArray)env->NewGlobalRef(buf); + env->DeleteLocalRef(buf); jclass cls = env->GetObjectClass(_input_stream); MID_mark = env->GetMethodID(cls, "mark", "(I)V"); @@ -112,6 +114,7 @@ JavaInputStream::JavaInputStream(JNIEnv *env, jobject is) : assert(MID_reset); MID_skip = env->GetMethodID(cls, "skip", "(J)J"); assert(MID_skip); + env->DeleteLocalRef(cls); // Mark start of stream, so we can reset back to it. // readlimit is set to something bigger than anything we might @@ -142,7 +145,9 @@ uint32 JavaInputStream::read(void *dataPtr, uint32 dataSize) { _buflen = dataSize; env->DeleteGlobalRef(_buf); - _buf = static_cast<jbyteArray>(env->NewGlobalRef(env->NewByteArray(_buflen))); + jobject buf = env->NewByteArray(_buflen); + _buf = static_cast<jbyteArray>(env->NewGlobalRef(buf)); + env->DeleteLocalRef(buf); } jint ret = env->CallIntMethod(_input_stream, MID_read, _buf, 0, dataSize); @@ -290,6 +295,7 @@ AssetFdReadStream::AssetFdReadStream(JNIEnv *env, jobject assetfd) : jclass cls = env->GetObjectClass(_assetfd); MID_close = env->GetMethodID(cls, "close", "()V"); assert(MID_close); + env->DeleteLocalRef(cls); jmethodID MID_getStartOffset = env->GetMethodID(cls, "getStartOffset", "()J"); @@ -311,8 +317,10 @@ AssetFdReadStream::AssetFdReadStream(JNIEnv *env, jobject assetfd) : jclass fd_cls = env->GetObjectClass(javafd); jfieldID FID_descriptor = env->GetFieldID(fd_cls, "descriptor", "I"); assert(FID_descriptor); + env->DeleteLocalRef(fd_cls); _fd = env->GetIntField(javafd, FID_descriptor); + env->DeleteLocalRef(javafd); } AssetFdReadStream::~AssetFdReadStream() { @@ -382,6 +390,7 @@ AndroidAssetArchive::AndroidAssetArchive(jobject am) { MID_list = env->GetMethodID(cls, "list", "(Ljava/lang/String;)[Ljava/lang/String;"); assert(MID_list); + env->DeleteLocalRef(cls); } AndroidAssetArchive::~AndroidAssetArchive() { @@ -481,8 +490,10 @@ Common::SeekableReadStream *AndroidAssetArchive::createReadStreamForMember(const env->ExceptionClear(); else if (afd != 0) { // success :) + Common::SeekableReadStream *stream = new AssetFdReadStream(env, afd); env->DeleteLocalRef(jpath); - return new AssetFdReadStream(env, afd); + env->DeleteLocalRef(afd); + return stream; } // ... and fallback to normal open() if that doesn't work @@ -498,7 +509,10 @@ Common::SeekableReadStream *AndroidAssetArchive::createReadStreamForMember(const return 0; } - return new JavaInputStream(env, is); + Common::SeekableReadStream *stream = new JavaInputStream(env, is); + env->DeleteLocalRef(jpath); + env->DeleteLocalRef(is); + return stream; } #endif |