Fixes potential global reference leak on Android, by Philipp Wiesemann
authorGabriel Jacobo <gabomdq@gmail.com>
Sun, 27 Jan 2013 21:43:20 -0300
changeset 6828 ac7f004fb63c
parent 6827 80a13e92ca35
child 6829 36ce2e6166e7
Fixes potential global reference leak on Android, by Philipp Wiesemann
src/core/android/SDL_android.cpp
--- a/src/core/android/SDL_android.cpp	Sun Jan 27 15:56:28 2013 -0800
+++ b/src/core/android/SDL_android.cpp	Sun Jan 27 21:43:20 2013 -0300
@@ -593,7 +593,6 @@
         goto fallback;
     }
 
-    ctx->hidden.androidio.assetFileDescriptorRef = mEnv->NewGlobalRef(inputStream);
     mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getStartOffset", "()J");
     ctx->hidden.androidio.offset = mEnv->CallLongMethod(inputStream, mid);
     if (Android_JNI_ExceptionOccurred()) {
@@ -602,7 +601,6 @@
 
     mid = mEnv->GetMethodID(mEnv->GetObjectClass(inputStream), "getDeclaredLength", "()J");
     ctx->hidden.androidio.size = mEnv->CallLongMethod(inputStream, mid);
-    
     if (Android_JNI_ExceptionOccurred()) {
         goto fallback;
     }
@@ -612,6 +610,7 @@
     fdCls = mEnv->GetObjectClass(fd);
     descriptor = mEnv->GetFieldID(fdCls, "descriptor", "I");
     ctx->hidden.androidio.fd = mEnv->GetIntField(fd, descriptor);
+    ctx->hidden.androidio.assetFileDescriptorRef = mEnv->NewGlobalRef(inputStream);
 
     // Seek to the correct offset in the file.
     lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);