From b3d6de4b7c823a1028bc204ebd41e180b64101d2 Mon Sep 17 00:00:00 2001 From: clay_shooter <> Date: Sun, 2 Oct 2011 15:51:20 +0000 Subject: [PATCH] 3412922Fix for: When a DispatchEvent is created with a COM object, the COM object is never released totally, and the destructor function is never called --- jacob/docs/ReleaseNotes.html | 4 ++++ jacob/jni/DispatchEvents.cpp | 3 +++ jacob/jni/EventProxy.cpp | 2 ++ jacob/jni/EventProxy.h | 4 +++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jacob/docs/ReleaseNotes.html b/jacob/docs/ReleaseNotes.html index a909f40..054b85b 100644 --- a/jacob/docs/ReleaseNotes.html +++ b/jacob/docs/ReleaseNotes.html @@ -15,6 +15,10 @@

Tracked Changes

Bugs + + 3412922 + (M1)Fix for: When a DispatchEvent is created with a COM object, the COM object is never released totally, and the destructor function is never called. +     diff --git a/jacob/jni/DispatchEvents.cpp b/jacob/jni/DispatchEvents.cpp index 082a041..71a063b 100644 --- a/jacob/jni/DispatchEvents.cpp +++ b/jacob/jni/DispatchEvents.cpp @@ -153,6 +153,9 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release { EventProxy *ep = extractProxy(env, _this); if (ep) { + // Disconnect must be called to reduce the ref count to the EventProxy otherwise + // the destructor will never be called (to actually do the disconnect) + ep->Disconnect(); // SF 3412922 // this is the line that blows up in IETest ep->Release(); putProxy(env, _this, NULL); diff --git a/jacob/jni/EventProxy.cpp b/jacob/jni/EventProxy.cpp index 496e8fc..7c035b6 100644 --- a/jacob/jni/EventProxy.cpp +++ b/jacob/jni/EventProxy.cpp @@ -100,6 +100,8 @@ EventProxy::~EventProxy() void EventProxy::Disconnect() { if (connected) { + // insure we don't call Unadvise twice + connected = 0; pCP->Unadvise(dwEventCookie); } } diff --git a/jacob/jni/EventProxy.h b/jacob/jni/EventProxy.h index e0c79ac..fb02ed3 100644 --- a/jacob/jni/EventProxy.h +++ b/jacob/jni/EventProxy.h @@ -50,7 +50,6 @@ class EventProxy : public IDispatch JavaVM *jvm; // The java vm we are running void convertJavaVariant(VARIANT *java, VARIANT *com); void Connect(JNIEnv *env); - void Disconnect(); public: // constuct with a global JNI ref to a sink object // to which we will delegate event callbacks @@ -98,4 +97,7 @@ class EventProxy : public IDispatch // These are the actual supported methods STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID , DISPID *); STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *); + // SF 3412922 make public to support cleanup from DispatchEvents + void Disconnect(); + };