Bug 1004669 - Fix leaks in MediaTaskQueue::Dispatch(). r=cpearce

This commit is contained in:
JW Wang 2014-05-11 20:12:00 +02:00
Родитель 545faaa4e4
Коммит 96a12f389c
3 изменённых файлов: 11 добавлений и 12 удалений

Просмотреть файл

@ -245,14 +245,9 @@ MediaDecoderStateMachine::~MediaDecoderStateMachine()
NS_ASSERTION(!mPendingWakeDecoder.get(), NS_ASSERTION(!mPendingWakeDecoder.get(),
"WakeDecoder should have been revoked already"); "WakeDecoder should have been revoked already");
if (mDecodeTaskQueue) { MOZ_ASSERT(!mDecodeTaskQueue, "Should be released in SHUTDOWN");
mDecodeTaskQueue->Shutdown(); // No need to cancel the timer here for we've done that in SHUTDOWN.
mDecodeTaskQueue = nullptr; MOZ_ASSERT(!mTimer, "Should be released in SHUTDOWN");
}
// No need to cancel the timer here for we've done that in
// TimeoutExpired() triggered by Shutdown()
mTimer = nullptr;
mReader = nullptr; mReader = nullptr;
#ifdef XP_WIN #ifdef XP_WIN
@ -1584,13 +1579,13 @@ MediaDecoderStateMachine::DispatchDecodeTasksIfNeeded()
return; return;
} }
mIsReaderIdle = needIdle; mIsReaderIdle = needIdle;
nsRefPtr<nsIRunnable> event; RefPtr<nsIRunnable> event;
if (mIsReaderIdle) { if (mIsReaderIdle) {
event = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::SetReaderIdle); event = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::SetReaderIdle);
} else { } else {
event = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::SetReaderActive); event = NS_NewRunnableMethod(this, &MediaDecoderStateMachine::SetReaderActive);
} }
if (NS_FAILED(mDecodeTaskQueue->Dispatch(event)) && if (NS_FAILED(mDecodeTaskQueue->Dispatch(event.forget())) &&
mState != DECODER_STATE_SHUTDOWN) { mState != DECODER_STATE_SHUTDOWN) {
NS_WARNING("Failed to dispatch event to set decoder idle state"); NS_WARNING("Failed to dispatch event to set decoder idle state");
} }
@ -2149,6 +2144,7 @@ nsresult MediaDecoderStateMachine::RunStateMachine()
ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor()); ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
// Wait for the thread decoding to exit. // Wait for the thread decoding to exit.
mDecodeTaskQueue->Shutdown(); mDecodeTaskQueue->Shutdown();
mDecodeTaskQueue = nullptr;
mReader->ReleaseMediaResources(); mReader->ReleaseMediaResources();
} }
// Now that those threads are stopped, there's no possibility of // Now that those threads are stopped, there's no possibility of
@ -2172,6 +2168,9 @@ nsresult MediaDecoderStateMachine::RunStateMachine()
// state machine. // state machine.
GetStateMachineThread()->Dispatch( GetStateMachineThread()->Dispatch(
new nsDispatchDisposeEvent(mDecoder, this), NS_DISPATCH_NORMAL); new nsDispatchDisposeEvent(mDecoder, this), NS_DISPATCH_NORMAL);
mTimer->Cancel();
mTimer = nullptr;
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -27,7 +27,7 @@ MediaTaskQueue::~MediaTaskQueue()
} }
nsresult nsresult
MediaTaskQueue::Dispatch(nsIRunnable* aRunnable) MediaTaskQueue::Dispatch(TemporaryRef<nsIRunnable> aRunnable)
{ {
MonitorAutoLock mon(mQueueMonitor); MonitorAutoLock mon(mQueueMonitor);
if (mIsShutdown) { if (mIsShutdown) {

Просмотреть файл

@ -31,7 +31,7 @@ public:
MediaTaskQueue(TemporaryRef<SharedThreadPool> aPool); MediaTaskQueue(TemporaryRef<SharedThreadPool> aPool);
nsresult Dispatch(nsIRunnable* aRunnable); nsresult Dispatch(TemporaryRef<nsIRunnable> aRunnable);
// Removes all pending tasks from the task queue, and blocks until // Removes all pending tasks from the task queue, and blocks until
// the currently running task (if any) finishes. // the currently running task (if any) finishes.