From 74bc96ce3c689f5aa197835d3dc71ddf99f4dec6 Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Wed, 14 Sep 2005 18:18:43 +0000 Subject: [PATCH] Bug 308404 Access violation [@ ntdll!RtlDeleteCriticalSection+0x0000000f] r=darin sr=darin git-svn-id: svn://10.0.0.236/trunk@180221 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/threads/nsThread.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mozilla/xpcom/threads/nsThread.cpp b/mozilla/xpcom/threads/nsThread.cpp index 7048716805c..06fae2920a5 100644 --- a/mozilla/xpcom/threads/nsThread.cpp +++ b/mozilla/xpcom/threads/nsThread.cpp @@ -286,9 +286,17 @@ nsThread::Init(nsIRunnable* runnable, mDead = PR_FALSE; mThread = PR_CreateThread(PR_USER_THREAD, Main, this, priority, scope, state, stackSize); + /* As soon as we PR_Unlock(mStartLock), if mThread was successfully + * created, it could run and exit very quickly. In which case, it + * would null mThread and therefore if we check if (mThread) we could + * confuse a successfully created, yet already exited thread with + * OOM - failure to create the thread. So instead we store a local thr + * which we check to see if we really failed to create the thread. + */ + PRThread *thr = mThread; PR_Unlock(mStartLock); - if (mThread == nsnull) { + if (thr == nsnull) { mDead = PR_TRUE; // otherwise cleared in nsThread::Exit mRunnable = nsnull; // otherwise cleared in nsThread::Main(when done) PR_DestroyLock(mStartLock);