Bug 1183920: Properly delete MediaResource when released on non main thread. r=cpearce

Leak was not detected as it was registered via NS_LOG_RELEASE.
This commit is contained in:
Jean-Yves Avenard 2015-07-15 10:51:02 +10:00
parent 072a8b1aa1
commit 8080a286fd

View File

@ -50,20 +50,14 @@ namespace mozilla {
void
MediaResource::Destroy()
{
// If we're being destroyed on a non-main thread, we AddRef again and
// use a proxy to release the MediaResource on the main thread, where
// the MediaResource is deleted. This ensures we only delete the
// MediaResource on the main thread.
if (!NS_IsMainThread()) {
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
NS_ENSURE_TRUE_VOID(mainThread);
nsRefPtr<MediaResource> doomed(this);
if (NS_FAILED(NS_ProxyRelease(mainThread, doomed, true))) {
NS_WARNING("Failed to proxy release to main thread!");
}
} else {
// Ensures we only delete the MediaResource on the main thread.
if (NS_IsMainThread()) {
delete this;
return;
}
nsCOMPtr<nsIRunnable> destroyRunnable =
NS_NewNonOwningRunnableMethod(this, &MediaResource::Destroy);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(destroyRunnable)));
}
NS_IMPL_ADDREF(MediaResource)