From 00b2c57d723d22cb8846c8ab9e8bc4aa61a47975 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.org" Date: Fri, 15 Jun 2007 16:23:45 +0000 Subject: [PATCH] Landing fix for bug 342810. Fixing leak of nsRunnable (huge leak on some flash sites). Patch by jmathies@mozilla.com, r+sr=jst@mozilla.com git-svn-id: svn://10.0.0.236/trunk@228121 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/src/nsPluginNativeWindowOS2.cpp | 47 ++++++++++--------- .../base/src/nsPluginNativeWindowWin.cpp | 41 +++++++++------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp b/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp index 3c487b996d7..9f4f060479e 100644 --- a/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp @@ -73,10 +73,10 @@ public: void Init(const PluginWindowWeakRef &ref, HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); void Clear(); HWND GetWnd() { return mWnd; }; - ULONG GetMsg() { return mMsg; }; + ULONG GetMsg() { return mMsg; }; MPARAM GetWParam() { return mWParam; }; MPARAM GetLParam() { return mLParam; }; - PRBool InUse() { return (mWnd!=NULL || mMsg!=0); }; + PRBool InUse() { return (mWnd!=NULL); }; NS_DECL_NSIRUNNABLE @@ -86,7 +86,6 @@ protected: ULONG mMsg; MPARAM mWParam; MPARAM mLParam; - PRBool mIsAlloced; }; PluginWindowEvent::PluginWindowEvent() @@ -97,16 +96,13 @@ PluginWindowEvent::PluginWindowEvent() void PluginWindowEvent::Clear() { mWnd = NULL; - mMsg = 0; - mWParam = 0; - mLParam = 0; } void PluginWindowEvent::Init(const PluginWindowWeakRef &ref, HWND aWnd, ULONG aMsg, MPARAM mp1, MPARAM mp2) { - NS_ASSERTION(aWnd!=NULL && aMsg!=0, "invalid plugin event value"); - NS_ASSERTION(mWnd==NULL && mMsg==0 && mWParam==0 && mLParam==0,"event already in use"); + NS_ASSERTION(aWnd != NULL, "invalid plugin event value"); + NS_ASSERTION(mWnd == NULL, "event already in use"); mPluginWindowRef = ref; mWnd = aWnd; mMsg = aMsg; @@ -139,8 +135,10 @@ private: public: // locals PFNWP GetWindowProc(); - already_AddRefed GetPluginWindowEvent(HWND aWnd, ULONG aMsg, - MPARAM mp1, MPARAM mp2); + PluginWindowEvent* GetPluginWindowEvent(HWND aWnd, + ULONG aMsg, + MPARAM mp1, + MPARAM mp2); private: PFNWP mPluginWinProc; @@ -272,7 +270,7 @@ NS_IMETHODIMP PluginWindowEvent::Run() return NS_OK; } -already_AddRefed +PluginWindowEvent* nsPluginNativeWindowOS2::GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM aMp1, MPARAM aMp2) { if (!mWeakRef) { @@ -282,24 +280,29 @@ nsPluginNativeWindowOS2::GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM aMp1 } PluginWindowEvent *event; - if (!mCachedPluginWindowEvent || mCachedPluginWindowEvent->InUse()) { - // We have the ability to alloc if needed in case in the future some plugin - // should post multiple PostMessages. However, this could lead to many - // alloc's per second which could become a performance issue. If/when this - // is asserting then this needs to be studied. See bug 169247 - NS_ASSERTION(1, "possible plugin performance issue"); + + // We have the ability to alloc if needed in case in the future some plugin + // should post multiple PostMessages. However, this could lead to many + // alloc's per second which could become a performance issue. See bug 169247. + if (!mCachedPluginWindowEvent) + { event = new PluginWindowEvent(); - if (!event) - return nsnull; + if (!event) return nsnull; + mCachedPluginWindowEvent = event; } - else { + else if (mCachedPluginWindowEvent->InUse()) + { + event = new PluginWindowEvent(); + if (!event) return nsnull; + } + else + { event = mCachedPluginWindowEvent; } - NS_ADDREF(event); event->Init(mWeakRef, aWnd, aMsg, aMp1, aMp2); return event; -}; +} nsresult nsPluginNativeWindowOS2::CallSetWindow(nsCOMPtr &aPluginInstance) { diff --git a/mozilla/modules/plugin/base/src/nsPluginNativeWindowWin.cpp b/mozilla/modules/plugin/base/src/nsPluginNativeWindowWin.cpp index 1c90754ae17..4d79aa2f2fc 100644 --- a/mozilla/modules/plugin/base/src/nsPluginNativeWindowWin.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginNativeWindowWin.cpp @@ -79,7 +79,7 @@ public: UINT GetMsg() { return mMsg; }; WPARAM GetWParam() { return mWParam; }; LPARAM GetLParam() { return mLParam; }; - PRBool InUse() { return (mWnd!=NULL || mMsg!=0); }; + PRBool InUse() { return (mWnd!=NULL); }; NS_DECL_NSIRUNNABLE @@ -89,7 +89,6 @@ protected: UINT mMsg; WPARAM mWParam; LPARAM mLParam; - PRBool mIsAlloced; }; PluginWindowEvent::PluginWindowEvent() @@ -108,8 +107,8 @@ void PluginWindowEvent::Clear() void PluginWindowEvent::Init(const PluginWindowWeakRef &ref, HWND aWnd, UINT aMsg, WPARAM aWParam, LPARAM aLParam) { - NS_ASSERTION(aWnd!=NULL && aMsg!=0, "invalid plugin event value"); - NS_ASSERTION(mWnd==NULL && mMsg==0 && mWParam==0 && mLParam==0,"event already in use"); + NS_ASSERTION(aWnd != NULL, "invalid plugin event value"); + NS_ASSERTION(mWnd == NULL, "event already in use"); mPluginWindowRef = ref; mWnd = aWnd; mMsg = aMsg; @@ -145,9 +144,10 @@ public: // locals WNDPROC GetPrevWindowProc(); WNDPROC GetWindowProc(); - already_AddRefed GetPluginWindowEvent(HWND aWnd, UINT aMsg, - WPARAM aWParam, - LPARAM aLParam); + PluginWindowEvent * GetPluginWindowEvent(HWND aWnd, + UINT aMsg, + WPARAM aWParam, + LPARAM aLParam); private: WNDPROC mPrevWinProc; @@ -439,7 +439,7 @@ NS_IMETHODIMP PluginWindowEvent::Run() return NS_OK; } -already_AddRefed +PluginWindowEvent * nsPluginNativeWindowWin::GetPluginWindowEvent(HWND aWnd, UINT aMsg, WPARAM aWParam, LPARAM aLParam) { if (!mWeakRef) { @@ -449,20 +449,25 @@ nsPluginNativeWindowWin::GetPluginWindowEvent(HWND aWnd, UINT aMsg, WPARAM aWPar } PluginWindowEvent *event; - if (!mCachedPluginWindowEvent || mCachedPluginWindowEvent->InUse()) { - // We have the ability to alloc if needed in case in the future some plugin - // should post multiple PostMessages. However, this could lead to many - // alloc's per second which could become a performance issue. If/when this - // is asserting then this needs to be studied. See bug 169247 - NS_ASSERTION(1, "possible plugin performance issue"); + + // We have the ability to alloc if needed in case in the future some plugin + // should post multiple PostMessages. However, this could lead to many + // alloc's per second which could become a performance issue. See bug 169247. + if (!mCachedPluginWindowEvent) + { event = new PluginWindowEvent(); - if (!event) - return nsnull; + if (!event) return nsnull; + mCachedPluginWindowEvent = event; } - else { + else if (mCachedPluginWindowEvent->InUse()) + { + event = new PluginWindowEvent(); + if (!event) return nsnull; + } + else + { event = mCachedPluginWindowEvent; } - NS_ADDREF(event); event->Init(mWeakRef, aWnd, aMsg, aWParam, aLParam); return event;