Address memory leak in SkScaledImageCache
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Dec 2013 18:48:08 +0000 (18:48 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Dec 2013 18:48:08 +0000 (18:48 +0000)
https://codereview.chromium.org/107443009/

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

src/core/SkScaledImageCache.cpp

index 2529b5f..45a5684 100644 (file)
@@ -428,7 +428,10 @@ SkScaledImageCache::ID* SkScaledImageCache::addAndLock(SkScaledImageCache::Rec*
     SkASSERT(rec);
     // See if we already have this key (racy inserts, etc.)
     Rec* existing = this->findAndLock(rec->fKey);
-    if (existing != NULL) {
+    if (NULL != existing) {
+        // Since we already have a matching entry, just delete the new one and return.
+        // Call sites cannot assume the passed in object will live past this call.
+        SkDELETE(rec);
         return rec_to_id(existing);
     }