From a9edb098e8f1ebd380fcc2a97bf55e0d9ea3490d Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Tue, 6 Apr 1999 04:57:44 +0000 Subject: [PATCH] Fixed refcount problems. --- base/src/nsThread.cpp | 5 +++-- xpcom/threads/nsThread.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/base/src/nsThread.cpp b/base/src/nsThread.cpp index 57fbe50f52f5..b65545342a8b 100644 --- a/base/src/nsThread.cpp +++ b/base/src/nsThread.cpp @@ -40,6 +40,7 @@ nsThread::Init(nsIRunnable* runnable, mRunnable = runnable; NS_ADDREF(mRunnable); + NS_ADDREF_THIS(); // released in nsIThread::Exit mThread = PR_CreateThread(type, Main, this, priority, scope, PR_JOINABLE_THREAD, stackSize); if (mThread == nsnull) @@ -49,6 +50,7 @@ nsThread::Init(nsIRunnable* runnable, nsThread::~nsThread() { + NS_IF_RELEASE(mRunnable); } void @@ -194,8 +196,6 @@ nsThread::RegisterThreadSelf() status = PR_SetThreadPrivate(kIThreadSelf, this); if (status != PR_SUCCESS) return NS_ERROR_FAILURE; - NS_ADDREF(this); // released in nsThread::Exit - return NS_OK; } @@ -218,6 +218,7 @@ nsIThread::GetCurrent(nsIThread* *result) thread = new nsThread(); if (thread == nsnull) return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(thread); thread->SetPRThread(PR_CurrentThread()); nsresult rv = thread->RegisterThreadSelf(); if (NS_FAILED(rv)) return rv; diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index 57fbe50f52f5..b65545342a8b 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -40,6 +40,7 @@ nsThread::Init(nsIRunnable* runnable, mRunnable = runnable; NS_ADDREF(mRunnable); + NS_ADDREF_THIS(); // released in nsIThread::Exit mThread = PR_CreateThread(type, Main, this, priority, scope, PR_JOINABLE_THREAD, stackSize); if (mThread == nsnull) @@ -49,6 +50,7 @@ nsThread::Init(nsIRunnable* runnable, nsThread::~nsThread() { + NS_IF_RELEASE(mRunnable); } void @@ -194,8 +196,6 @@ nsThread::RegisterThreadSelf() status = PR_SetThreadPrivate(kIThreadSelf, this); if (status != PR_SUCCESS) return NS_ERROR_FAILURE; - NS_ADDREF(this); // released in nsThread::Exit - return NS_OK; } @@ -218,6 +218,7 @@ nsIThread::GetCurrent(nsIThread* *result) thread = new nsThread(); if (thread == nsnull) return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(thread); thread->SetPRThread(PR_CurrentThread()); nsresult rv = thread->RegisterThreadSelf(); if (NS_FAILED(rv)) return rv;