Bug 339947 - Java XPCOM proxies can get used (resurrected) after having been garbage collected causing VM crash. XULRunner only. patch by ttudor/jhpedemonte, r=jhpedemonte.

Original committer: pedemont%us.ibm.com
Original revision: 1.8
Original date: 2006/06/06 17:13:18
This commit is contained in:
pedemont%us.ibm.com 2006-09-27 15:11:25 +00:00
Родитель a06c1feba3
Коммит e0c3c82983
1 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -60,12 +60,17 @@ nsJavaXPTCStubWeakRef::nsJavaXPTCStubWeakRef(jobject aJavaObject,
nsJavaXPTCStub* aXPTCStub)
: mXPTCStub(aXPTCStub)
{
mWeakRef = GetJNIEnv()->NewWeakGlobalRef(aJavaObject);
JNIEnv* env = GetJNIEnv();
jobject weakref = env->NewObject(weakReferenceClass,
weakReferenceConstructorMID, aJavaObject);
mWeakRef = env->NewGlobalRef(weakref);
}
nsJavaXPTCStubWeakRef::~nsJavaXPTCStubWeakRef()
{
GetJNIEnv()->DeleteWeakGlobalRef(mWeakRef);
JNIEnv* env = GetJNIEnv();
env->CallVoidMethod(mWeakRef, clearReferentMID);
env->DeleteGlobalRef(mWeakRef);
mXPTCStub->ReleaseWeakRef();
}
@ -82,8 +87,9 @@ nsJavaXPTCStubWeakRef::QueryReferent(const nsIID& aIID, void** aInstancePtr)
// Is weak ref still valid?
// We create a strong local ref to make sure Java object isn't garbage
// collected during this call.
jobject javaObject = GetJNIEnv()->NewLocalRef(mWeakRef);
if (!javaObject)
JNIEnv* env = GetJNIEnv();
jobject javaObject = env->CallObjectMethod(mWeakRef, getReferentMID);
if (env->IsSameObject(javaObject, NULL))
return NS_ERROR_NULL_POINTER;
// Java object has not been garbage collected, so return QI from XPTCStub.