Bug 906445. Some speculative fixes to guard against dereferencing nullptrs. r=Bas
authorNicholas Cameron <ncameron@mozilla.com>
Mon, 09 Sep 2013 09:06:50 +1200
changeset 146099 ca1ff26fc797d4ae44b8655b890f6a12f724de71
parent 146098 c4a605e6da428aab746a032d9ad29144d314d78a
child 146100 08144be95a5c45e9290a5b30077abb5abf7715e7
push id25240
push useremorley@mozilla.com
push dateMon, 09 Sep 2013 12:09:06 +0000
treeherdermozilla-central@9846f07d5867 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs906445
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 906445. Some speculative fixes to guard against dereferencing nullptrs. r=Bas
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -115,16 +115,17 @@ DeprecatedTextureClientD3D11::EnsureAllo
   RefPtr<IDXGIResource> resource;
   mTexture->QueryInterface((IDXGIResource**)byRef(resource));
 
   HANDLE sharedHandle;
   hr = resource->GetSharedHandle(&sharedHandle);
 
   if (FAILED(hr)) {
     LOGD3D11("Error getting shared handle for texture.");
+    return false;
   }
 
   mDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle,
                                        aType == gfxASurface::CONTENT_COLOR_ALPHA);
 
   mContentType = aType;
   return true;
 }
@@ -169,19 +170,20 @@ DeprecatedTextureClientD3D11::SetDescrip
 
   if (aDescriptor.type() == SurfaceDescriptor::T__None) {
     return;
   }
 
   MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
   ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
 
-  device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(),
-                             __uuidof(ID3D10Texture2D),
-                             (void**)(ID3D10Texture2D**)byRef(mTexture));
+  HRESULT hr = device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(),
+                                          __uuidof(ID3D10Texture2D),
+                                          (void**)(ID3D10Texture2D**)byRef(mTexture));
+  NS_WARN_IF_FALSE(mTexture && SUCCEEDED(hr), "Could not open shared resource");
 }
 
 void
 DeprecatedTextureClientD3D11::EnsureSurface()
 {
   if (mSurface) {
     return;
   }
@@ -416,39 +418,51 @@ DeprecatedTextureHostDXGID3D11::Unlock()
 
 void
 DeprecatedTextureHostDXGID3D11::UpdateImpl(const SurfaceDescriptor& aImage,
                                            nsIntRegion* aRegion,
                                            nsIntPoint* aOffset)
 {
   MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
 
-  mDevice->OpenSharedResource((HANDLE)aImage.get_SurfaceDescriptorD3D10().handle(),
-                              __uuidof(ID3D11Texture2D),
-                              (void**)(ID3D11Texture2D**)byRef(mTextures[0]));
+  HRESULT hr =mDevice->OpenSharedResource((HANDLE)aImage.get_SurfaceDescriptorD3D10().handle(),
+                                          __uuidof(ID3D11Texture2D),
+                                          (void**)(ID3D11Texture2D**)byRef(mTextures[0]));
+  if (!mTextures[0] || FAILED(hr)) {
+    NS_WARNING("Could not open shared resource");
+    mSize = IntSize(0, 0);
+    return;
+  }
+
   mFormat = aImage.get_SurfaceDescriptorD3D10().hasAlpha() ? FORMAT_B8G8R8A8 : FORMAT_B8G8R8X8;
 
   D3D11_TEXTURE2D_DESC desc;
   mTextures[0]->GetDesc(&desc);
 
   mSize = IntSize(desc.Width, desc.Height);
 }
 
 void
 DeprecatedTextureHostDXGID3D11::LockTexture()
 {
+  if (!mTextures[0]) {
+    return;
+  }
   RefPtr<IDXGIKeyedMutex> mutex;
   mTextures[0]->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
 
   mutex->AcquireSync(0, INFINITE);
 }
 
 void
 DeprecatedTextureHostDXGID3D11::ReleaseTexture()
 {
+  if (!mTextures[0]) {
+    return;
+  }
   RefPtr<IDXGIKeyedMutex> mutex;
   mTextures[0]->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
 
   mutex->ReleaseSync(0);
 }
 
 void
 DeprecatedTextureHostYCbCrD3D11::SetCompositor(Compositor* aCompositor)