Fix leak when closing window that has live refresh timers. Bug 312769,

r=darin, sr=bryner
This commit is contained in:
bzbarsky@mit.edu
2005-10-18 01:48:22 +00:00
parent dc49d1afbd
commit a74da2e81a
2 changed files with 21 additions and 13 deletions

View File

@@ -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<nsISupports> element;
mRefreshURIList->GetElementAt(--n, getter_AddRefs(element));
nsCOMPtr<nsITimer> timer(do_QueryInterface(element));
nsCOMPtr<nsITimer> 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;
}

View File

@@ -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