Title: [189170] trunk/Source/WebCore
Revision
189170
Author
mcatanz...@igalia.com
Date
2015-08-31 09:32:59 -0700 (Mon, 31 Aug 2015)

Log Message

[Freetype] FontCache::strengthOfFirstAlias leaks an FcPattern
https://bugs.webkit.org/show_bug.cgi?id=148624

Reviewed by Martin Robinson.

Using the normal RefPtr constructor causes the FcPattern to be reffed one extra time. Even
though the FcPattern is intentionally leaked to FcFontSetAdd down below, the FcPattern has
its own refcount and now it's screwed up. Just completely stop using RefPtr for these
FcPatterns, since the potential for confusion regarding leakRef combined with Fontconfig
refcounting far outweighs the benefit of using a smart pointer.

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::strengthOfFirstAlias):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (189169 => 189170)


--- trunk/Source/WebCore/ChangeLog	2015-08-31 16:30:03 UTC (rev 189169)
+++ trunk/Source/WebCore/ChangeLog	2015-08-31 16:32:59 UTC (rev 189170)
@@ -1,3 +1,19 @@
+2015-08-31  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        [Freetype] FontCache::strengthOfFirstAlias leaks an FcPattern
+        https://bugs.webkit.org/show_bug.cgi?id=148624
+
+        Reviewed by Martin Robinson.
+
+        Using the normal RefPtr constructor causes the FcPattern to be reffed one extra time. Even
+        though the FcPattern is intentionally leaked to FcFontSetAdd down below, the FcPattern has
+        its own refcount and now it's screwed up. Just completely stop using RefPtr for these
+        FcPatterns, since the potential for confusion regarding leakRef combined with Fontconfig
+        refcounting far outweighs the benefit of using a smart pointer.
+
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::strengthOfFirstAlias):
+
 2015-08-31  Javier Fernandez  <jfernan...@igalia.com>
 
         [CSS Grid Layout] auto-margins alignment does not work for heights

Modified: trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (189169 => 189170)


--- trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2015-08-31 16:30:03 UTC (rev 189169)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2015-08-31 16:32:59 UTC (rev 189170)
@@ -225,17 +225,19 @@
 
     FcUniquePtr<FcLangSet> strongLangSet(FcLangSetCreate());
     FcLangSetAdd(strongLangSet.get(), reinterpret_cast<const FcChar8*>("nomatchlang"));
-    RefPtr<FcPattern> strong = adoptRef(FcPatternDuplicate(pattern.get()));
-    FcPatternAddLangSet(strong.get(), FC_LANG, strongLangSet.get());
+    // Ownership of this FcPattern will be transferred with FcFontSetAdd.
+    FcPattern* strong = FcPatternDuplicate(pattern.get());
+    FcPatternAddLangSet(strong, FC_LANG, strongLangSet.get());
 
     FcUniquePtr<FcLangSet> weakLangSet(FcLangSetCreate());
     FcLangSetAdd(weakLangSet.get(), reinterpret_cast<const FcChar8*>("matchlang"));
-    RefPtr<FcPattern> weak(FcPatternCreate());
-    FcPatternAddString(weak.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>("nomatchstring"));
-    FcPatternAddLangSet(weak.get(), FC_LANG, weakLangSet.get());
+    // Ownership of this FcPattern will be transferred via FcFontSetAdd.
+    FcPattern* weak = FcPatternCreate();
+    FcPatternAddString(weak, FC_FAMILY, reinterpret_cast<const FcChar8*>("nomatchstring"));
+    FcPatternAddLangSet(weak, FC_LANG, weakLangSet.get());
 
-    FcFontSetAdd(fontSet.get(), strong.leakRef());
-    FcFontSetAdd(fontSet.get(), weak.leakRef());
+    FcFontSetAdd(fontSet.get(), strong);
+    FcFontSetAdd(fontSet.get(), weak);
 
     // Add 'matchlang' to the copy of the pattern.
     FcPatternAddLangSet(pattern.get(), FC_LANG, weakLangSet.get());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to