Bug 717178. Part 3: gfxGDIFont should pass ownership of its mFont to cairo_font_face_t. r=jrmuizel
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 01 Jan 2013 17:53:39 +1300
changeset 126392 4bab6b6a32f3e69efaa428ec572366af37b47ae7
parent 126391 b1453ec5b550523e4bdfda6061d44168b13b466d
child 126393 1322a7cadd5662534f1b1281da36445be7e0475f
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs717178
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 717178. Part 3: gfxGDIFont should pass ownership of its mFont to cairo_font_face_t. r=jrmuizel
gfx/thebes/gfxGDIFont.cpp
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -57,19 +57,16 @@ gfxGDIFont::gfxGDIFont(GDIFontEntry *aFo
 gfxGDIFont::~gfxGDIFont()
 {
     if (mScaledFont) {
         cairo_scaled_font_destroy(mScaledFont);
     }
     if (mFontFace) {
         cairo_font_face_destroy(mFontFace);
     }
-    if (mFont) {
-        ::DeleteObject(mFont);
-    }
     delete mMetrics;
 }
 
 void
 gfxGDIFont::CreatePlatformShaper()
 {
     mPlatformShaper = new gfxGDIShaper(this);
 }
@@ -372,16 +369,17 @@ gfxGDIFont::Initialize()
 
             // GetTextMetrics can fail if the font file has been removed
             // or corrupted recently.
             BOOL result = GetTextMetrics(dc.GetDC(), &metrics);
             if (!result) {
                 NS_WARNING("Missing or corrupt font data, fasten your seatbelt");
                 mIsValid = false;
                 memset(mMetrics, 0, sizeof(*mMetrics));
+                ::DeleteObject(mFont);
                 return;
             }
 
             mMetrics->xHeight =
                 ROUND((float)metrics.tmAscent * DEFAULT_XHEIGHT_FACTOR);
             mMetrics->superscriptOffset = mMetrics->xHeight;
             mMetrics->subscriptOffset = mMetrics->xHeight;
             mMetrics->strikeoutSize = 1;
@@ -434,16 +432,19 @@ gfxGDIFont::Initialize()
         SanitizeMetrics(mMetrics, GetFontEntry()->mIsBadUnderlineFont);
     }
 
     if (IsSyntheticBold()) {
         mMetrics->aveCharWidth += GetSyntheticBoldOffset();
         mMetrics->maxAdvance += GetSyntheticBoldOffset();
     }
 
+    // This transfers ownership of mFont to mFontFace, making
+    // mFontFace responsible for deleting mFont so we don't have to
+    // (and shouldn't, since we don't know exactly when mFontFace will die).
     mFontFace = cairo_win32_font_face_create_for_logfontw_hfont(&logFont,
                                                                 mFont);
 
     cairo_matrix_t sizeMatrix, ctm;
     cairo_matrix_init_identity(&ctm);
     cairo_matrix_init_scale(&sizeMatrix, mAdjustedSize, mAdjustedSize);
 
     if (useCairoFakeItalic) {