aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkData.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-24 22:38:39 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-24 22:38:39 +0000
commit709ca75f032d7c60eb53c5840524a875a3a6cdb1 (patch)
tree0e9d511e02bdcf5e1ef443b7fac4c8e8694092a4 /src/core/SkData.cpp
parent3a9ade7f37a819c3290f5a668bb11c5e61bfa93f (diff)
SkOnce: add option to call another cleanup function once at exit.
Use this to clean up empty SkData and SkPathRef. Current leaks: Leaked SkRefCntBase: 40 Leaked SkFlattenable: 32 Leaked SkPixelRef: 32 Leaked SkMallocPixelRef: 32 Leaked SkFontConfigInterface: 1 Leaked SkWeakRefCnt: 1 Leaked SkTypeface: 1 Leaked SkFontMgr: 1 Leaked SkDataTable: 3 Leaked SkImage: 1 Leaked ???: 1 Leaked ???: 1 BUG=skia: R=halcanary@google.com, reed@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/132803005 git-svn-id: http://skia.googlecode.com/svn/trunk@13180 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkData.cpp')
-rw-r--r--src/core/SkData.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index fd963a9ff5..176e93c47b 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -48,16 +48,18 @@ size_t SkData::copyRange(size_t offset, size_t length, void* buffer) const {
///////////////////////////////////////////////////////////////////////////////
-void SkData::NewEmptyImpl(SkData** empty) {
- *empty = new SkData(NULL, 0, NULL, NULL);
+static SkData* gEmptyDataRef = NULL;
+static void cleanup_gEmptyDataRef() { gEmptyDataRef->unref(); }
+
+void SkData::NewEmptyImpl(int) {
+ gEmptyDataRef = new SkData(NULL, 0, NULL, NULL);
}
SkData* SkData::NewEmpty() {
- static SkData* gEmptyRef;
SK_DECLARE_STATIC_ONCE(once);
- SkOnce(&once, SkData::NewEmptyImpl, &gEmptyRef);
- gEmptyRef->ref();
- return gEmptyRef;
+ SkOnce(&once, SkData::NewEmptyImpl, 0, cleanup_gEmptyDataRef);
+ gEmptyDataRef->ref();
+ return gEmptyDataRef;
}
// assumes fPtr was allocated via sk_malloc