Bug 1100448 - Protect against null cairo_surface_t when getting the underlying surface from DrawTargetCairo. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Mon, 17 Nov 2014 21:41:41 +0000
changeset 241249 e5326d6771d31d94e11b2715048590b3437b49f0
parent 241248 e89322d9b9482e788cfa4cac5c674ea1ab3d36fe
child 241250 88d56477715377e854259b5423580ca4fdc1dbe2
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs1100448
milestone36.0a1
Bug 1100448 - Protect against null cairo_surface_t when getting the underlying surface from DrawTargetCairo. r=Bas
gfx/thebes/gfxWindowsPlatform.cpp
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -82,26 +82,28 @@ using namespace mozilla::widget;
 using namespace mozilla::image;
 
 DCFromDrawTarget::DCFromDrawTarget(DrawTarget& aDrawTarget)
 {
   mDC = nullptr;
   if (aDrawTarget.GetBackendType() == BackendType::CAIRO) {
     cairo_surface_t *surf = (cairo_surface_t*)
         aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_SURFACE);
-    cairo_surface_type_t surfaceType = cairo_surface_get_type(surf);
-    if (surfaceType == CAIRO_SURFACE_TYPE_WIN32 ||
-        surfaceType == CAIRO_SURFACE_TYPE_WIN32_PRINTING) {
-      mDC = cairo_win32_surface_get_dc(surf);
-      mNeedsRelease = false;
-      SaveDC(mDC);
-      cairo_t* ctx = (cairo_t*)
-          aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT);
-      cairo_scaled_font_t* scaled = cairo_get_scaled_font(ctx);
-      cairo_win32_scaled_font_select_font(scaled, mDC);
+    if (surf) {
+      cairo_surface_type_t surfaceType = cairo_surface_get_type(surf);
+      if (surfaceType == CAIRO_SURFACE_TYPE_WIN32 ||
+          surfaceType == CAIRO_SURFACE_TYPE_WIN32_PRINTING) {
+        mDC = cairo_win32_surface_get_dc(surf);
+        mNeedsRelease = false;
+        SaveDC(mDC);
+        cairo_t* ctx = (cairo_t*)
+            aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT);
+        cairo_scaled_font_t* scaled = cairo_get_scaled_font(ctx);
+        cairo_win32_scaled_font_select_font(scaled, mDC);
+      }
     }
     if (!mDC) {
       mDC = GetDC(nullptr);
       SetGraphicsMode(mDC, GM_ADVANCED);
       mNeedsRelease = true;
     }
   }
 }