From b19fc8d9eb1f3e840f8d3aba2bca82d3d5ba5deb Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 18 Oct 2005 01:48:22 +0000 Subject: [PATCH] Fix leak when closing window that has live refresh timers. Bug 312769, r=darin, sr=bryner git-svn-id: svn://10.0.0.236/trunk@182434 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 31 +++++++++++++++++++--------- mozilla/docshell/base/nsWebShell.cpp | 3 --- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index e6a855eae93..b1a74ea0f26 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3555,7 +3555,11 @@ nsDocShell::Destroy() // required to break ref cycle mSecurityUI = nsnull; - + + // Cancel any timers that were set for this docshell; this is needed + // to break the cycle between us and the timers. + CancelRefreshURITimers(); + return NS_OK; } @@ -4437,25 +4441,32 @@ NS_IMETHODIMP nsDocShell::SetupRefreshURI(nsIChannel * aChannel) return rv; } -NS_IMETHODIMP -nsDocShell::CancelRefreshURITimers() +static void +DoCancelRefreshURITimers(nsISupportsArray* aTimerList) { - if (!mRefreshURIList) - return NS_OK; + if (!aTimerList) + return; PRUint32 n=0; - mRefreshURIList->Count(&n); + aTimerList->Count(&n); while (n) { - nsCOMPtr element; - mRefreshURIList->GetElementAt(--n, getter_AddRefs(element)); - nsCOMPtr timer(do_QueryInterface(element)); + nsCOMPtr timer(do_QueryElementAt(aTimerList, --n)); - mRefreshURIList->RemoveElementAt(n); // bye bye owning timer ref + aTimerList->RemoveElementAt(n); // bye bye owning timer ref if (timer) timer->Cancel(); } +} + +NS_IMETHODIMP +nsDocShell::CancelRefreshURITimers() +{ + DoCancelRefreshURITimers(mRefreshURIList); + DoCancelRefreshURITimers(mSavedRefreshURIList); + mRefreshURIList = nsnull; + mSavedRefreshURIList = nsnull; return NS_OK; } diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 75ae7b6f291..acd32441368 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -179,9 +179,6 @@ nsWebShell::~nsWebShell() { Destroy(); - // Cancel any timers that were set for this loader. - CancelRefreshURITimers(); - ++mRefCnt; // following releases can cause this destructor to be called // recursively if the refcount is allowed to remain 0