Permalink
Browse files

FIREBREATH-176: Fix memory leak w/ JSAPI references on ActiveX

  • Loading branch information...
1 parent d20f2c9 commit 3f458b94bd601b7fabdbf70bd94bd7fae22b7d5a @taxilian taxilian committed Jun 7, 2012
@@ -356,7 +356,7 @@ IDispatchEx* FB::ActiveX::ActiveXBrowserHost::getJSAPIWrapper( const FB::JSAPIWe
IDispatchEx* ret(NULL);
FB::JSAPIPtr ptr(api.lock());
if (!ptr)
- return getFactoryInstance()->createCOMJSObject(shared_from_this(), api, false);
+ return getFactoryInstance()->createCOMJSObject(shared_from_this(), api, autoRelease);
IDispatchExRefMap::iterator fnd = m_cachedIDispatch.find(ptr.get());
if (fnd != m_cachedIDispatch.end()) {
@@ -55,6 +55,13 @@ namespace FB {
obj->setAPI(api, host);
obj->m_autoRelease = auto_release;
+ if (auto_release) {
+ FB::JSAPIPtr tmp(api.lock());
+ // If we are auto-releasing it then we need to retain it as well
+ if (tmp) {
+ host->releaseJSAPIPtr(tmp);
+ }
+ }
IDispatchEx *retval;
hr = obj->QueryInterface(IID_IDispatchEx, (void **)&retval);
@@ -251,7 +251,6 @@ namespace FB { namespace ActiveX
} else {
if (obj) {
// Add obj to the list of shared_ptrs that browserhost keeps
- host->retainJSAPIPtr(obj);
outVar = host->getJSAPIWrapper(obj, true);
outVar.pdispVal->Release();
} else {
@@ -273,7 +272,7 @@ namespace FB { namespace ActiveX
outVar = api->getIDispatch();
} else {
if (obj) {
- outVar = host->getJSAPIWrapper(obj);
+ outVar = host->getJSAPIWrapper(obj, false);
outVar.pdispVal->Release();
} else {
outVar.ChangeType(VT_NULL);
@@ -295,8 +294,7 @@ namespace FB { namespace ActiveX
} else {
if (obj) {
FB::JSAPIPtr ptr(var.convert_cast<FB::JSAPIPtr>());
- host->retainJSAPIPtr(ptr);
- outVar = getFactoryInstance()->createCOMJSObject(host, ptr);
+ outVar = getFactoryInstance()->createCOMJSObject(host, ptr, true);
outVar.pdispVal->Release();
} else {
outVar.ChangeType(VT_NULL);

0 comments on commit 3f458b9

Please sign in to comment.