Bug 1139824 - Track construction/destruction of the font table wrappers attached to hb_blob objects, to enable leak detection. r=jdaggett

This commit is contained in:
Jonathan Kew 2015-03-09 12:16:22 +00:00
parent 5ae116f0aa
commit b0f0a419bc
2 changed files with 35 additions and 2 deletions

View File

@ -457,9 +457,12 @@ class FontTableRec {
public:
FontTableRec(IDWriteFontFace *aFontFace, void *aContext)
: mFontFace(aFontFace), mContext(aContext)
{ }
{
MOZ_COUNT_CTOR(FontTableRec);
}
~FontTableRec() {
MOZ_COUNT_DTOR(FontTableRec);
mFontFace->ReleaseFontTable(mContext);
}

View File

@ -323,10 +323,35 @@ MacOSFontEntry::GetFontRef()
return mFontRef;
}
// For a logging build, we wrap the CFDataRef in a FontTableRec so that we can
// use the MOZ_COUNT_[CD]TOR macros in it. A release build without logging
// does not get this overhead.
class FontTableRec {
public:
explicit FontTableRec(CFDataRef aDataRef)
: mDataRef(aDataRef)
{
MOZ_COUNT_CTOR(FontTableRec);
}
~FontTableRec() {
MOZ_COUNT_DTOR(FontTableRec);
::CFRelease(mDataRef);
}
private:
CFDataRef mDataRef;
};
/*static*/ void
MacOSFontEntry::DestroyBlobFunc(void* aUserData)
{
#ifdef NS_BUILD_REFCNT_LOGGING
FontTableRec *ftr = static_cast<FontTableRec*>(aUserData);
delete ftr;
#else
::CFRelease((CFDataRef)aUserData);
#endif
}
hb_blob_t *
@ -342,7 +367,12 @@ MacOSFontEntry::GetFontTable(uint32_t aTag)
return hb_blob_create((const char*)::CFDataGetBytePtr(dataRef),
::CFDataGetLength(dataRef),
HB_MEMORY_MODE_READONLY,
(void*)dataRef, DestroyBlobFunc);
#ifdef NS_BUILD_REFCNT_LOGGING
new FontTableRec(dataRef),
#else
(void*)dataRef,
#endif
DestroyBlobFunc);
}
return nullptr;