When cloning into an SkPicture, clear its data.
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 2 Nov 2012 20:51:19 +0000 (20:51 +0000)
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 2 Nov 2012 20:51:19 +0000 (20:51 +0000)
Prevents a memory leak if the caller clones into an SkPicture
that already has a playback or record.

Review URL: https://codereview.appspot.com/6813081

git-svn-id: http://skia.googlecode.com/svn/trunk@6282 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkPicture.cpp

index 410952479bb9460f95759a18d9c84f8c1c875239..564a829d339c3eec2f267f02ae1550268d2e033c 100644 (file)
@@ -157,6 +157,12 @@ void SkPicture::clone(SkPicture* pictures, int count) const {
         clone->fHeight = fHeight;
         clone->fRecord = NULL;
 
+        if (NULL != clone->fRecord) {
+            clone->fRecord->unref();
+            clone->fRecord = NULL;
+        }
+        SkDELETE(clone->fPlayback);
+
         /*  We want to copy the src's playback. However, if that hasn't been built
             yet, we need to fake a call to endRecording() without actually calling
             it (since it is destructive, and we don't want to change src).