Bug 625617: Message manager leaks JSObject holder class. r=smaug a=bsmedberg
authorKyle Huey <khuey@kylehuey.com>
Fri, 21 Jan 2011 17:51:41 -0500
changeset 61117 7940a0d8ad48cb4250e6f3e05fb34a0083159a38
parent 61116 84f88de431f83fc941b0cfc5ddc7640477f46c4d
child 61118 ac1ddab6de5909de9a7046103cb7bd764100dc04
push idunknown
push userunknown
push dateunknown
reviewerssmaug, bsmedberg
bugs625617
milestone2.0b10pre
Bug 625617: Message manager leaks JSObject holder class. r=smaug a=bsmedberg
content/base/src/nsFrameMessageManager.cpp
content/base/src/nsFrameMessageManager.h
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -576,16 +576,17 @@ nsFrameScriptExecutor::DestroyCx()
 
 static PLDHashOperator
 CachedScriptUnrooter(const nsAString& aKey,
                        nsFrameScriptExecutorJSObjectHolder*& aData,
                        void* aUserArg)
 {
   JSContext* cx = static_cast<JSContext*>(aUserArg);
   JS_RemoveObjectRoot(cx, &(aData->mObject));
+  delete aData;
   return PL_DHASH_REMOVE;
 }
 
 // static
 void
 nsFrameScriptExecutor::Shutdown()
 {
   if (sCachedScripts) {
--- a/content/base/src/nsFrameMessageManager.h
+++ b/content/base/src/nsFrameMessageManager.h
@@ -179,26 +179,32 @@ public:
   static nsFrameMessageManager* sParentProcessManager;
   static nsFrameMessageManager* sChildProcessManager;
 };
 
 class nsScriptCacheCleaner;
 
 struct nsFrameScriptExecutorJSObjectHolder
 {
-  nsFrameScriptExecutorJSObjectHolder(JSObject* aObject) : mObject(aObject) {}
+  nsFrameScriptExecutorJSObjectHolder(JSObject* aObject) : mObject(aObject)
+  { MOZ_COUNT_CTOR(nsFrameScriptExecutorJSObjectHolder); }
+  ~nsFrameScriptExecutorJSObjectHolder()
+  { MOZ_COUNT_DTOR(nsFrameScriptExecutorJSObjectHolder); }
   JSObject* mObject;
 };
 
 class nsFrameScriptExecutor
 {
 public:
   static void Shutdown();
 protected:
-  nsFrameScriptExecutor() : mCx(nsnull) {}
+  nsFrameScriptExecutor() : mCx(nsnull)
+  { MOZ_COUNT_CTOR(nsFrameScriptExecutor); }
+  ~nsFrameScriptExecutor()
+  { MOZ_COUNT_DTOR(nsFrameScriptExecutor); }
   void DidCreateCx();
   // Call this when you want to destroy mCx.
   void DestroyCx();
   void LoadFrameScriptInternal(const nsAString& aURL);
   nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
   JSContext* mCx;
   nsCOMPtr<nsIPrincipal> mPrincipal;
   static nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>* sCachedScripts;