From 9fc5c68823c7e39e4769a41713ce070a7780df29 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Tue, 12 Nov 2013 15:25:29 +0000 Subject: Fix leak detected in FontMgrMatchGM::onDraw by Valgrind. git-svn-id: http://skia.googlecode.com/svn/trunk@12242 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/fontmgr.cpp | 10 ++++------ include/ports/SkFontMgr.h | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp index 06288b2ab3..4b64821e7e 100644 --- a/gm/fontmgr.cpp +++ b/gm/fontmgr.cpp @@ -162,18 +162,16 @@ protected: "Helvetica Neue", "Arial" }; - SkFontStyleSet* fset = NULL; + SkAutoTUnref fset; for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { - fset = fFM->matchFamily(gNames[i]); - if (fset && fset->count() > 0) { + fset.reset(fFM->matchFamily(gNames[i])); + if (fset->count() > 0) { break; } } - - if (NULL == fset) { + if (NULL == fset.get()) { return; } - SkAutoUnref aur(fset); canvas->translate(20, 40); this->exploreFamily(canvas, paint, fset); diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index 6e9f56f545..accb0c5860 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -41,6 +41,10 @@ public: void getFamilyName(int index, SkString* familyName); SkFontStyleSet* createStyleSet(int index); + /** + * The caller must call unref() on the returned object. + * Never returns NULL; will return an empty set if the name is not found. + */ SkFontStyleSet* matchFamily(const char familyName[]); /** @@ -89,6 +93,7 @@ protected: virtual void onGetFamilyName(int index, SkString* familyName) = 0; virtual SkFontStyleSet* onCreateStyleSet(int index) = 0; + /** May return NULL if the name is not found. */ virtual SkFontStyleSet* onMatchFamily(const char familyName[]) = 0; virtual SkTypeface* onMatchFamilyStyle(const char familyName[], -- cgit v1.2.3