зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1039034 - Don't leak add-on interpositions at shutdown (r=bholley)
This commit is contained in:
Родитель
40d22b0bb7
Коммит
b7d71d4781
|
@ -27,6 +27,26 @@ XPCWrappedNativeScope* XPCWrappedNativeScope::gScopes = nullptr;
|
||||||
XPCWrappedNativeScope* XPCWrappedNativeScope::gDyingScopes = nullptr;
|
XPCWrappedNativeScope* XPCWrappedNativeScope::gDyingScopes = nullptr;
|
||||||
XPCWrappedNativeScope::InterpositionMap* XPCWrappedNativeScope::gInterpositionMap = nullptr;
|
XPCWrappedNativeScope::InterpositionMap* XPCWrappedNativeScope::gInterpositionMap = nullptr;
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(XPCWrappedNativeScope::ClearInterpositionsObserver, nsIObserver)
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
XPCWrappedNativeScope::ClearInterpositionsObserver::Observe(nsISupports *subject,
|
||||||
|
const char *topic,
|
||||||
|
const char16_t *data)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
|
||||||
|
|
||||||
|
// The interposition map holds strong references to interpositions, which
|
||||||
|
// may themselves be involved in cycles. We need to drop these strong
|
||||||
|
// references before the cycle collector shuts down. Otherwise we'll
|
||||||
|
// leak. This observer always runs before CC shutdown.
|
||||||
|
if (gInterpositionMap)
|
||||||
|
delete gInterpositionMap;
|
||||||
|
|
||||||
|
nsContentUtils::UnregisterShutdownObserver(this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
RemoteXULForbidsXBLScope(nsIPrincipal *aPrincipal, HandleObject aGlobal)
|
RemoteXULForbidsXBLScope(nsIPrincipal *aPrincipal, HandleObject aGlobal)
|
||||||
{
|
{
|
||||||
|
@ -671,9 +691,6 @@ XPCWrappedNativeScope::SystemIsBeingShutDown()
|
||||||
|
|
||||||
// Now it is safe to kill all the scopes.
|
// Now it is safe to kill all the scopes.
|
||||||
KillDyingScopes();
|
KillDyingScopes();
|
||||||
|
|
||||||
if (gInterpositionMap)
|
|
||||||
delete gInterpositionMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -707,6 +724,9 @@ XPCWrappedNativeScope::SetAddonInterposition(JSAddonId *addonId,
|
||||||
if (!gInterpositionMap) {
|
if (!gInterpositionMap) {
|
||||||
gInterpositionMap = new InterpositionMap();
|
gInterpositionMap = new InterpositionMap();
|
||||||
gInterpositionMap->init();
|
gInterpositionMap->init();
|
||||||
|
|
||||||
|
// Make sure to clear the map at shutdown.
|
||||||
|
nsContentUtils::RegisterShutdownObserver(new ClearInterpositionsObserver());
|
||||||
}
|
}
|
||||||
if (interp) {
|
if (interp) {
|
||||||
return gInterpositionMap->put(addonId, interp);
|
return gInterpositionMap->put(addonId, interp);
|
||||||
|
|
|
@ -110,6 +110,7 @@
|
||||||
#include "nsIInterfaceInfo.h"
|
#include "nsIInterfaceInfo.h"
|
||||||
#include "nsIXPCScriptable.h"
|
#include "nsIXPCScriptable.h"
|
||||||
#include "nsIJSRuntimeService.h"
|
#include "nsIJSRuntimeService.h"
|
||||||
|
#include "nsIObserver.h"
|
||||||
#include "nsWeakReference.h"
|
#include "nsWeakReference.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsXPTCUtils.h"
|
#include "nsXPTCUtils.h"
|
||||||
|
@ -1176,6 +1177,14 @@ protected:
|
||||||
XPCWrappedNativeScope(); // not implemented
|
XPCWrappedNativeScope(); // not implemented
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class ClearInterpositionsObserver MOZ_FINAL : public nsIObserver {
|
||||||
|
~ClearInterpositionsObserver() {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIOBSERVER
|
||||||
|
};
|
||||||
|
|
||||||
static XPCWrappedNativeScope* gScopes;
|
static XPCWrappedNativeScope* gScopes;
|
||||||
static XPCWrappedNativeScope* gDyingScopes;
|
static XPCWrappedNativeScope* gDyingScopes;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче