Bug 996487: don't null out mThread while committing thread suicide r=bsmedberg

This commit is contained in:
Randell Jesup 2014-04-22 15:32:13 -04:00
parent 8772be6b45
commit a39021aa83
4 changed files with 12 additions and 2 deletions

View File

@ -521,7 +521,11 @@ AudioInitTask::Run()
MOZ_ASSERT(mThread);
if (NS_IsMainThread()) {
mThread->Shutdown(); // can't Shutdown from the thread itself, darn
mThread = nullptr;
// Don't null out mThread!
// See bug 999104. We must hold a ref to the thread across Dispatch()
// since the internal mThread ref could be released while processing
// the Dispatch(), and Dispatch/PutEvent itself doesn't hold a ref; it
// assumes the caller does.
return NS_OK;
}

View File

@ -445,6 +445,7 @@ public:
// Can't add 'this' as the event to run, since mThread may not be set yet
nsresult rv = NS_NewNamedThread("CubebInit", getter_AddRefs(mThread));
if (NS_SUCCEEDED(rv)) {
// Note: event must not null out mThread!
rv = mThread->Dispatch(this, NS_DISPATCH_NORMAL);
}
return rv;

View File

@ -46,7 +46,11 @@ CryptoTask::Run()
if (mThread) {
// Don't leak threads!
mThread->Shutdown(); // can't Shutdown from the thread itself, darn
mThread = nullptr;
// Don't null out mThread!
// See bug 999104. We must hold a ref to the thread across Dispatch()
// since the internal mThread ref could be released while processing
// the Dispatch(), and Dispatch/PutEvent itself doesn't hold a ref; it
// assumes the caller does.
}
}

View File

@ -42,6 +42,7 @@ public:
// Can't add 'this' as the event to run, since mThread may not be set yet
nsresult rv = NS_NewNamedThread(taskThreadName, getter_AddRefs(mThread));
if (NS_SUCCEEDED(rv)) {
// Note: event must not null out mThread!
rv = mThread->Dispatch(this, NS_DISPATCH_NORMAL);
}
return rv;