From aa033a1a7abe63d7634d7da77537831f91ae68dc Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 27 Sep 2006 15:09:38 +0000 Subject: [PATCH] Store a global weak ref to the Java object rather than the 'address' returned by the JVM Original committer: pedemont%us.ibm.com Original revision: 1.4 Original date: 2004/09/30 23:34:47 git-svn-id: svn://10.0.0.236/trunk@212499 18797224-902f-48f8-a5cc-f745e15eee43 --- .../java/xpcom/src/nsJavaInterfaces.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mozilla/extensions/java/xpcom/src/nsJavaInterfaces.cpp b/mozilla/extensions/java/xpcom/src/nsJavaInterfaces.cpp index 7824b254bab..0012cdc2b58 100644 --- a/mozilla/extensions/java/xpcom/src/nsJavaInterfaces.cpp +++ b/mozilla/extensions/java/xpcom/src/nsJavaInterfaces.cpp @@ -519,7 +519,22 @@ XPCOM_NATIVE(FinalizeStub) (JNIEnv *env, jclass that, jobject aJavaObject) if (isCopy) env->ReleaseStringUTFChars(name, javaObjectName); #endif - nsISupports* xpcomObj = RemoveXPCOMBinding(env, aJavaObject); - NS_RELEASE(xpcomObj); + + void* obj = GetMatchingXPCOMObject(env, aJavaObject); + RemoveJavaXPCOMBinding(env, aJavaObject, nsnull); + + nsISupports* xpcom_obj = nsnull; + if (IsXPTCStub(obj)) { + GetXPTCStubAddr(obj)->QueryInterface(NS_GET_IID(nsISupports), + (void**) &xpcom_obj); + } else { + JavaXPCOMInstance* inst = (JavaXPCOMInstance*) obj; + xpcom_obj = inst->GetInstance(); + // XXX Getting some odd thread issues when calling delete. Addreffing for + // now to work around the errors. +// NS_ADDREF(inst); + delete inst; + } + NS_RELEASE(xpcom_obj); }