Bug 623451: Don't double-release surfaces. r=jrmuizel a=b
authorChris Jones <jones.chris.g@gmail.com>
Tue, 11 Jan 2011 15:34:31 -0600
changeset 60321 7cad0cd7b62e3dd9088be1f9e7855718040dd7a9
parent 60320 735dfa53d77994504211873a3135115d6c813782
child 60322 bddac4e2bf745c8389c383f0ea3b2a54d887f4bd
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel, b
bugs623451
milestone2.0b10pre
Bug 623451: Don't double-release surfaces. r=jrmuizel a=b
gfx/layers/ipc/ShadowLayersParent.cpp
gfx/thebes/gfxSharedImageSurface.cpp
--- a/gfx/layers/ipc/ShadowLayersParent.cpp
+++ b/gfx/layers/ipc/ShadowLayersParent.cpp
@@ -410,16 +410,20 @@ ShadowLayersParent::RecvUpdate(const Inf
       const OpPaintCanvas& op = edit.get_OpPaintCanvas();
       ShadowLayerParent* shadow = AsShadowLayer(op);
       ShadowCanvasLayer* canvas =
         static_cast<ShadowCanvasLayer*>(shadow->AsLayer());
 
       nsRefPtr<gfxSharedImageSurface> newFront =
         gfxSharedImageSurface::Open(op.newFrontBuffer());
       nsRefPtr<gfxSharedImageSurface> newBack = canvas->Swap(newFront);
+      if (newFront == newBack) {
+        newFront.forget();
+      }
+
       canvas->Updated(op.updated());
 
       replyv.push_back(OpBufferSwap(shadow, NULL,
                                     newBack->GetShmem()));
 
       break;
     }
     case Edit::TOpPaintImage: {
@@ -428,16 +432,19 @@ ShadowLayersParent::RecvUpdate(const Inf
       const OpPaintImage& op = edit.get_OpPaintImage();
       ShadowLayerParent* shadow = AsShadowLayer(op);
       ShadowImageLayer* image =
         static_cast<ShadowImageLayer*>(shadow->AsLayer());
 
       nsRefPtr<gfxSharedImageSurface> newFront =
         gfxSharedImageSurface::Open(op.newFrontBuffer());
       nsRefPtr<gfxSharedImageSurface> newBack = image->Swap(newFront);
+      if (newFront == newBack) {
+        newFront.forget();
+      }
 
       replyv.push_back(OpBufferSwap(shadow, NULL,
                                     newBack->GetShmem()));
 
       break;
     }
 
     default:
--- a/gfx/thebes/gfxSharedImageSurface.cpp
+++ b/gfx/thebes/gfxSharedImageSurface.cpp
@@ -56,30 +56,33 @@ static SharedImageInfo*
 GetShmInfoPtr(const Shmem& aShmem)
 {
     return reinterpret_cast<SharedImageInfo*>
         (aShmem.get<char>() + aShmem.Size<char>() - sizeof(SharedImageInfo));
 }
 
 gfxSharedImageSurface::~gfxSharedImageSurface()
 {
+    MOZ_COUNT_DTOR(gfxSharedImageSurface);
 }
 
 /*static*/ PRBool
 gfxSharedImageSurface::IsSharedImage(gfxASurface* aSurface)
 {
     return (aSurface
             && aSurface->GetType() == gfxASurface::SurfaceTypeImage
             && aSurface->GetData(&SHM_KEY));
 }
 
 gfxSharedImageSurface::gfxSharedImageSurface(const gfxIntSize& aSize,
                                              gfxImageFormat aFormat,
                                              const Shmem& aShmem)
 {
+    MOZ_COUNT_CTOR(gfxSharedImageSurface);
+
     mSize = aSize;
     mFormat = aFormat;
     mStride = ComputeStride(aSize, aFormat);
     mShmem = aShmem;
     mData = aShmem.get<unsigned char>();
     cairo_surface_t *surface =
         cairo_image_surface_create_for_data(mData,
                                             (cairo_format_t)mFormat,