Fix memory leak in SkSpecialSurface
authorrobertphillips <robertphillips@google.com>
Thu, 4 Feb 2016 22:59:58 +0000 (14:59 -0800)
committerCommit bot <commit-bot@chromium.org>
Thu, 4 Feb 2016 22:59:58 +0000 (14:59 -0800)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1666373002

TBR=jcgregorio@google.com
NOTRY=true

Review URL: https://codereview.chromium.org/1666373002

src/core/SkSpecialSurface.cpp

index 5d57dcf..548552c 100644 (file)
@@ -54,7 +54,7 @@ SkCanvas* SkSpecialSurface::getCanvas() {
 SkSpecialImage* SkSpecialSurface::newImageSnapshot() {
     SkSpecialImage* image = as_SB(this)->onNewImageSnapshot();
     as_SB(this)->reset();
-    return SkSafeRef(image);   // the caller will call unref() to balance this
+    return image;   // the caller gets the creation ref
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -110,7 +110,7 @@ class SkSpecialSurface_Gpu : public SkSpecialSurface_Base {
 public:
     SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurfaceProps* props)
         : INHERITED(subset, props)
-        , fTexture(texture) {
+        , fTexture(SkRef(texture)) {
 
         SkASSERT(fTexture->asRenderTarget());
 
@@ -151,7 +151,7 @@ SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context,
         return nullptr;
     }
 
-    GrTexture* temp = context->textureProvider()->createApproxTexture(desc);
+    SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture(desc));
     if (!temp) {
         return nullptr;
     }