From 5ea802bd9a5ac6218fafff9f3dd1c1a41183b919 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 18 Feb 2015 13:35:30 +1300 Subject: [PATCH] Bug 1128170 - Use UniquePtr for TextureClient KeepAlive objects to make sure we don't leak them. r=jrmuizel --- gfx/layers/client/TextureClient.cpp | 9 ++++----- gfx/layers/client/TextureClient.h | 2 +- gfx/layers/d3d11/TextureD3D11.cpp | 4 ++-- gfx/layers/d3d9/TextureD3D9.cpp | 2 +- gfx/layers/d3d9/TextureD3D9.h | 4 +++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 59348da94af9..fee69052f4aa 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -86,7 +86,6 @@ public: TextureChild() : mForwarder(nullptr) , mTextureClient(nullptr) - , mKeep(nullptr) , mIPCOpen(false) { } @@ -135,7 +134,7 @@ private: RefPtr mForwarder; RefPtr mWaitForRecycle; TextureClient* mTextureClient; - KeepAlive* mKeep; + UniquePtr mKeep; bool mIPCOpen; friend class TextureClient; @@ -154,7 +153,7 @@ TextureChild::ActorDestroy(ActorDestroyReason why) mTextureClient->mActor = nullptr; } mWaitForRecycle = nullptr; - delete mKeep; + mKeep = nullptr; } // static @@ -496,11 +495,11 @@ TextureClient::~TextureClient() } void -TextureClient::KeepUntilFullDeallocation(KeepAlive* aKeep) +TextureClient::KeepUntilFullDeallocation(UniquePtr aKeep) { MOZ_ASSERT(mActor); MOZ_ASSERT(!mActor->mKeep); - mActor->mKeep = aKeep; + mActor->mKeep = Move(aKeep); } void TextureClient::ForceRemove(bool sync) diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 19a50191dbfe..856ac851678b 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -403,7 +403,7 @@ public: * It's a temporary hack to ensure that DXGI textures don't get destroyed * between serialization and deserialization. */ - void KeepUntilFullDeallocation(KeepAlive* aKeep); + void KeepUntilFullDeallocation(UniquePtr aKeep); /** * Create and init the TextureChild/Parent IPDL actor pair. diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 9789e994fab0..555168b760c6 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -179,9 +179,9 @@ TextureClientD3D11::~TextureClientD3D11() { if (mActor) { if (mTexture) { - KeepUntilFullDeallocation(new TKeepAlive(mTexture10)); + KeepUntilFullDeallocation(MakeUnique>(mTexture10)); } else if (mTexture10) { - KeepUntilFullDeallocation(new TKeepAlive(mTexture)); + KeepUntilFullDeallocation(MakeUnique>(mTexture)); } } #ifdef DEBUG diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index 1db07aefa0f0..c8bf9273a75a 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -739,7 +739,7 @@ SharedTextureClientD3D9::SharedTextureClientD3D9(ISurfaceAllocator* aAllocator, SharedTextureClientD3D9::~SharedTextureClientD3D9() { if (mTexture && mActor) { - KeepUntilFullDeallocation(new TKeepAlive(mTexture)); + KeepUntilFullDeallocation(MakeUnique>(mTexture)); } if (mTexture) { gfxWindowsPlatform::sD3D9SharedTextureUsed -= mDesc.Width * mDesc.Height * 4; diff --git a/gfx/layers/d3d9/TextureD3D9.h b/gfx/layers/d3d9/TextureD3D9.h index 6f4d239c472c..fb0d40479380 100644 --- a/gfx/layers/d3d9/TextureD3D9.h +++ b/gfx/layers/d3d9/TextureD3D9.h @@ -266,7 +266,9 @@ public: mTexture = aTexture; mHandle = aSharedHandle; mDesc = aDesc; - gfxWindowsPlatform::sD3D9SharedTextureUsed += mDesc.Width * mDesc.Height * 4; + if (mTexture) { + gfxWindowsPlatform::sD3D9SharedTextureUsed += mDesc.Width * mDesc.Height * 4; + } } virtual gfx::IntSize GetSize() const