Permalink
Browse files

FIREBREATH-176: Fix memory leak w/ multiple references to JSAPIAuto o…

…n NPAPI browsers
  • Loading branch information...
1 parent 41e12d3 commit d20f2c9c957494b6959780f88e757a1ac8769e3f @taxilian taxilian committed Jun 7, 2012
Showing with 9 additions and 4 deletions.
  1. +7 −0 src/NpapiCore/NPJavascriptObject.cpp
  2. +1 −3 src/NpapiCore/NPVariantUtil.h
  3. +1 −1 src/NpapiCore/NpapiBrowserHost.cpp
@@ -28,6 +28,13 @@ NPJavascriptObject *NPJavascriptObject::NewObject(const NpapiBrowserHostPtr& hos
// If obj is null, return null; it's probably during shutdown
obj->setAPI(api, host);
obj->m_autoRelease = auto_release;
+ if (auto_release) {
+ // If we're autoreleasing it we need to autoretain it
+ FB::JSAPIPtr api_strong(api.lock());
+ if (api_strong) {
+ host->retainJSAPIPtr(api_strong);
+ }
+ }
}
return obj;
}
@@ -208,7 +208,6 @@ namespace FB { namespace Npapi
outObj = tmpObj->getNPObject();
host->RetainObject(outObj);
} else {
- host->retainJSAPIPtr(obj);
outObj = host->getJSAPIWrapper(var.cast<FB::JSAPIPtr>(), true);
}
if (outObj) {
@@ -269,8 +268,7 @@ namespace FB { namespace Npapi
outObj = tmpObj->getNPObject();
host->RetainObject(outObj);
} else {
- host->retainJSAPIPtr(obj);
- outObj = NPJavascriptObject::NewObject(host, obj);
+ outObj = NPJavascriptObject::NewObject(host, obj, true);
}
npv.type = NPVariantType_Object;
@@ -784,7 +784,7 @@ NPJavascriptObject* FB::Npapi::NpapiBrowserHost::getJSAPIWrapper( const FB::JSAP
}
}
if (!ret) {
- ret = NPJavascriptObject::NewObject(FB::ptr_cast<NpapiBrowserHost>(shared_from_this()), api, true);
+ ret = NPJavascriptObject::NewObject(FB::ptr_cast<NpapiBrowserHost>(shared_from_this()), api, autoRelease);
if (ret)
m_cachedNPObject[ptr.get()] = ret->getWeakReference();
}

0 comments on commit d20f2c9

Please sign in to comment.