Bug 751262 - Don't pop the JNI local ref frame if pushing it failed. r=kats

This commit is contained in:
Brad Lassey 2012-05-08 20:21:36 -04:00
parent 8dbe9d436b
commit 9d8cae7b2a

View File

@ -549,14 +549,14 @@ protected:
class AutoLocalJNIFrame {
public:
AutoLocalJNIFrame(int nEntries = 128)
: mEntries(nEntries)
: mEntries(nEntries), mHasFrameBeenPushed(false)
{
mJNIEnv = AndroidBridge::GetJNIEnv();
Push();
}
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 128)
: mEntries(nEntries)
: mEntries(nEntries), mHasFrameBeenPushed(false)
{
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
@ -568,7 +568,8 @@ public:
// any local refs that you need to keep around in global refs!
void Purge() {
if (mJNIEnv) {
mJNIEnv->PopLocalFrame(NULL);
if (mHasFrameBeenPushed)
mJNIEnv->PopLocalFrame(NULL);
Push();
}
}
@ -593,7 +594,8 @@ public:
CheckForException();
mJNIEnv->PopLocalFrame(NULL);
if (mHasFrameBeenPushed)
mJNIEnv->PopLocalFrame(NULL);
}
private:
@ -606,13 +608,15 @@ private:
// not hurt.
jint ret = mJNIEnv->PushLocalFrame(mEntries + 1);
NS_ABORT_IF_FALSE(ret == 0, "Failed to push local JNI frame");
if (ret < 0) {
if (ret < 0)
CheckForException();
}
else
mHasFrameBeenPushed = true;
}
int mEntries;
JNIEnv* mJNIEnv;
bool mHasFrameBeenPushed;
};
}