Bug 1061712 - Don't crash in DrawTargetDual::CreateSimilar if allocation fails. r=Bas, a=sledru
authorNicolas Silva <nsilva@mozilla.com>
Tue, 16 Sep 2014 14:29:40 +0200
changeset 216875 69047a750833
parent 216874 b6985e15046b
child 216876 4020480a6741
push id3951
push userryanvm@gmail.com
push date2014-09-29 18:48 +0000
treeherdermozilla-beta@19338c25065c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, sledru
bugs1061712
milestone33.0
Bug 1061712 - Don't crash in DrawTargetDual::CreateSimilar if allocation fails. r=Bas, a=sledru
gfx/2d/DrawTargetDual.cpp
--- a/gfx/2d/DrawTargetDual.cpp
+++ b/gfx/2d/DrawTargetDual.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
   * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      
 #include "DrawTargetDual.h"
 #include "Tools.h"
+#include "Logging.h"
 
 namespace mozilla {
 namespace gfx {
 
 class DualSurface
 {
 public:
   inline DualSurface(SourceSurface *aSurface)
@@ -181,13 +182,18 @@ DrawTargetDual::Mask(const Pattern &aSou
 }
 
 TemporaryRef<DrawTarget>
 DrawTargetDual::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
 {
   RefPtr<DrawTarget> dtA = mA->CreateSimilarDrawTarget(aSize, aFormat);
   RefPtr<DrawTarget> dtB = mB->CreateSimilarDrawTarget(aSize, aFormat);
 
+  if (!dtA || !dtB) {
+    gfxWarning() << "Failure to allocate a similar DrawTargetDual. Size: " << aSize;
+    return nullptr;
+  }
+
   return new DrawTargetDual(dtA, dtB);
 }
 
 }
 }