From dddb8e5b855cc6e1b15190504f327eace500d987 Mon Sep 17 00:00:00 2001 From: "rpotts%netscape.com" Date: Fri, 24 Jul 1998 05:39:18 +0000 Subject: [PATCH] Fixed up some reference counting issues... --- base/src/windows/nsTimer.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/base/src/windows/nsTimer.cpp b/base/src/windows/nsTimer.cpp index ed7bb8deeed3..670f2369fbd9 100644 --- a/base/src/windows/nsTimer.cpp +++ b/base/src/windows/nsTimer.cpp @@ -40,7 +40,7 @@ public: public: TimerImpl(); - ~TimerImpl(); + virtual ~TimerImpl(); virtual nsresult Init(nsTimerCallbackFunc aFunc, void *aClosure, @@ -186,12 +186,17 @@ TimerImpl::ProcessTimeouts(DWORD aNow) while(p) { // send it if(p->mFireTime < aNow) { + // Make sure that the timer cannot be deleted during the + // Fire(...) call which may release *all* other references + // to p... + NS_ADDREF(p); p->Fire(aNow); // Clear the timer. // Period synced. p->Cancel(); bCalledSync = TRUE; + NS_RELEASE(p); // Reset the loop (can't look at p->pNext now, and called // code may have added/cleared timers). @@ -221,10 +226,13 @@ TimerImpl::TimerImpl() mFunc = NULL; mCallback = NULL; mNext = NULL; + mClosure = nsnull; } TimerImpl::~TimerImpl() { + Cancel(); + NS_IF_RELEASE(mCallback); } nsresult @@ -246,6 +254,7 @@ TimerImpl::Init(nsITimerCallback *aCallback, PRUint32 aDelay) { mCallback = aCallback; + NS_ADDREF(mCallback); // mRepeat = aRepeat; return Init(aDelay);