Resource cache now explicitly takes ref of managed resources

https://codereview.appspot.com/6489085/



git-svn-id: http://skia.googlecode.com/svn/trunk@5407 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 8d55abb..74f9953 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1105,19 +1105,16 @@
             // whatever sizes GL gives us. In that case we query for the size.
             GrGLStencilBuffer::Format format = sFmt;
             get_stencil_rb_sizes(this->glInterface(), sbID, &format);
-            sb = SkNEW_ARGS(GrGLStencilBuffer,
-                            (this, sbID, width, height,
-                             samples, format));
+            SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer,
+                                                  (this, sbID, width, height,
+                                                  samples, format)));
             if (this->attachStencilBufferToRenderTarget(sb, rt)) {
                 fLastSuccessfulStencilFmtIdx = sIdx;
-                // This code transfers the creation ref to the
-                // cache and then adds a ref for the render target
                 sb->transferToCacheAndLock();
                 rt->setStencilBuffer(sb);
                 return true;
            }
            sb->abandon(); // otherwise we lose sbID
-           sb->unref();
         }
     }
     GL_CALL(DeleteRenderbuffers(1, &sbID));