Bug 1178816 - Fix a crash when DrawTargetD2D1 fails to initialize. r=milan
authorNicolas Silva <nsilva@mozilla.com>
Mon, 06 Jul 2015 17:57:03 +0200
changeset 275880 2a2556b4ed28af6da6180b33cbe2df438ad7f0cd
parent 275879 bb924c51e2849c40fbfae45a5727b8dcd2b855dc
child 275881 a61cdc2610c2e6eb7da3101bad7f3dbae8f62fcc
push id3246
push usergijskruitbosch@gmail.com
push dateTue, 07 Jul 2015 09:06:38 +0000
reviewersmilan
bugs1178816
milestone42.0a1
Bug 1178816 - Fix a crash when DrawTargetD2D1 fails to initialize. r=milan
gfx/2d/DrawTargetD2D1.cpp
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -45,17 +45,22 @@ DrawTargetD2D1::~DrawTargetD2D1()
     // MarkIndependent is running.
     RefPtr<SourceSurfaceD2D1> deathGrip = mSnapshot;
     // mSnapshot can be treated as independent of this DrawTarget since we know
     // this DrawTarget won't change again.
     deathGrip->MarkIndependent();
     // mSnapshot will be cleared now.
   }
 
-  mDC->EndDraw();
+  if (mDC) {
+    // The only way mDC can be null is if Init failed, but it can happen and the
+    // destructor is the only place where we need to check for it since the
+    // DrawTarget will destroyed right after Init fails.
+    mDC->EndDraw();
+  }
 
   // Targets depending on us can break that dependency, since we're obviously not going to
   // be modified in the future.
   for (auto iter = mDependentTargets.begin();
        iter != mDependentTargets.end(); iter++) {
     (*iter)->mDependingOnTargets.erase(this);
   }
   // Our dependencies on other targets no longer matter.