mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-06-06 16:38:55 +00:00
Properly delete MediaResource when released on non main thread
Fixes potential memory leak.
This commit is contained in:
@@ -53,20 +53,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)
|
||||
|
||||
Reference in New Issue
Block a user