Fix memory leak in BitmapHeapTest
authormtklein <mtklein@chromium.org>
Wed, 12 Nov 2014 18:09:10 +0000 (10:09 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 12 Nov 2014 18:09:11 +0000 (10:09 -0800)
BUG=skia:

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

tests/BitmapHeapTest.cpp

index f3385644bd132a33ff24c2d1571016711304fac6..c7d097278b3501a6765599642b34c16940f1a229 100644 (file)
 
 struct SimpleFlatController : public SkFlatController {
     SimpleFlatController() : SkFlatController() {}
-    virtual void* allocThrow(size_t bytes) SK_OVERRIDE { return sk_malloc_throw(bytes); }
-    virtual void unalloc(void* ptr) SK_OVERRIDE { sk_free(ptr); }
+    ~SimpleFlatController() { fAllocations.freeAll(); }
+    virtual void* allocThrow(size_t bytes) SK_OVERRIDE {
+        fAllocations.push(sk_malloc_throw(bytes));
+        return fAllocations.top();
+    }
+    virtual void unalloc(void*) SK_OVERRIDE { }
     void setBitmapStorage(SkBitmapHeap* h) { this->setBitmapHeap(h); }
+private:
+    SkTDArray<void*> fAllocations;
 };
 
 struct SkShaderTraits {