2009-03-16 Xan Lopez <xlopez@igalia.com>
authorxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Mar 2009 14:43:32 +0000 (14:43 +0000)
committerxan@webkit.org <xan@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Mar 2009 14:43:32 +0000 (14:43 +0000)
        Reviewed by Holger Freyther.

        https://bugs.webkit.org/show_bug.cgi?id=24592
        [GTK] Crash in FcPatternHash

        Sanitize memory management in gtk fonts.

        Release memory allocated by FontPlatformDataGtk in its own
        destructor instead of doing it from other classes, and add copy
        constructor and '=' operator to be able to track referenced
        objects properly.

        * platform/graphics/gtk/FontPlatformData.h:
        * platform/graphics/gtk/FontPlatformDataGtk.cpp:
        (WebCore::FontPlatformData::operator=):
        (WebCore::FontPlatformData::FontPlatformData):
        (WebCore::FontPlatformData::~FontPlatformData):
        * platform/graphics/gtk/SimpleFontDataGtk.cpp:
        (WebCore::SimpleFontData::platformDestroy):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@41762 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/gtk/FontPlatformData.h
WebCore/platform/graphics/gtk/FontPlatformDataGtk.cpp
WebCore/platform/graphics/gtk/SimpleFontDataGtk.cpp

index 38cf11eb371f19596bc57c147a2aa3fae4c35179..41e72b7ff01eb75a6faa0605639455d9e94b2553 100644 (file)
@@ -1,3 +1,25 @@
+2009-03-16  Xan Lopez  <xlopez@igalia.com>
+
+        Reviewed by Holger Freyther.
+
+        https://bugs.webkit.org/show_bug.cgi?id=24592
+        [GTK] Crash in FcPatternHash
+
+        Sanitize memory management in gtk fonts.
+
+        Release memory allocated by FontPlatformDataGtk in its own
+        destructor instead of doing it from other classes, and add copy
+        constructor and '=' operator to be able to track referenced
+        objects properly.
+
+        * platform/graphics/gtk/FontPlatformData.h:
+        * platform/graphics/gtk/FontPlatformDataGtk.cpp:
+        (WebCore::FontPlatformData::operator=):
+        (WebCore::FontPlatformData::FontPlatformData):
+        (WebCore::FontPlatformData::~FontPlatformData):
+        * platform/graphics/gtk/SimpleFontDataGtk.cpp:
+        (WebCore::SimpleFontData::platformDestroy):
+
 2009-03-17  Ariya Hidayat  <ariya.hidayat@nokia.com>
 
         Build fix for Qt < 4.5.
index efa5dd53e2a1e5ccbf4b6840810c6ffec26ea00a..20c52e53b5db1848aa190f8363d37971d8d08dd3 100644 (file)
@@ -74,6 +74,7 @@ public:
 
     FontPlatformData(float size, bool bold, bool italic);
     FontPlatformData(cairo_font_face_t* fontFace, int size, bool bold, bool italic);
+    FontPlatformData(const FontPlatformData&);
 
     ~FontPlatformData();
 
@@ -95,6 +96,7 @@ public:
     }
 
     bool operator==(const FontPlatformData&) const;
+    FontPlatformData& operator=(const FontPlatformData&);
     bool isHashTableDeletedValue() const {
 #if defined(USE_FREETYPE)
         return m_pattern == hashTableDeletedFontValue();
index 17d789b6ceb44e91b14764c87bf8446e82130cf0..17c9e8f6f2f2be3a52b13c30885384bded6e696a 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
  * Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com>
  * Copyright (C) 2007 Holger Hans Peter Freyther
+ * Copyright (C) 2009 Igalia S.L.
  * All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
@@ -161,6 +162,45 @@ FontPlatformData::FontPlatformData(cairo_font_face_t* fontFace, int size, bool b
     m_scaledFont = cairo_scaled_font_create(fontFace, &fontMatrix, &ctm, options);
 }
 
+FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other)
+{
+    // Check for self-assignment.
+    if (this == &other)
+        return *this;
+
+    m_size = other.m_size;
+    m_syntheticBold = other.m_syntheticBold;
+    m_syntheticOblique = other.m_syntheticOblique;
+
+    if (other.m_scaledFont)
+        cairo_scaled_font_reference (other.m_scaledFont);
+    if (m_scaledFont)
+        cairo_scaled_font_destroy(m_scaledFont);
+    m_scaledFont = other.m_scaledFont;
+
+    if (other.m_pattern)
+        FcPatternReference(other.m_pattern);
+    if (m_pattern)
+        FcPatternDestroy(m_pattern);
+    m_pattern = other.m_pattern;
+
+    if (m_fallbacks) {
+        FcFontSetDestroy(m_fallbacks);
+        // This will be re-created on demand.
+        m_fallbacks = 0;
+    }
+
+    return *this;
+}
+
+FontPlatformData::FontPlatformData(const FontPlatformData& other)
+    : m_pattern(0)
+    , m_fallbacks(0)
+    , m_scaledFont(0)
+{
+    *this = other;
+}
+
 bool FontPlatformData::init()
 {
     static bool initialized = false;
@@ -176,6 +216,20 @@ bool FontPlatformData::init()
 
 FontPlatformData::~FontPlatformData()
 {
+    if (m_pattern && ((FcPattern*)-1 != m_pattern)) {
+        FcPatternDestroy(m_pattern);
+        m_pattern = 0;
+    }
+
+    if (m_fallbacks) {
+        FcFontSetDestroy(m_fallbacks);
+        m_fallbacks = 0;
+    }
+
+    if (m_scaledFont) {
+        cairo_scaled_font_destroy(m_scaledFont);
+        m_scaledFont = 0;
+    }
 }
 
 bool FontPlatformData::isFixedPitch()
index 5207ba64ed224d449e511ae541183efec623444d..189b5f10aa50d5fe096e25563359c50ef1175e46 100644 (file)
@@ -64,24 +64,6 @@ void SimpleFontData::platformDestroy()
 {
     delete m_smallCapsFontData;
     m_smallCapsFontData = 0;
-
-    if (isCustomFont())
-        return;
-
-    if (m_font.m_pattern && ((FcPattern*)-1 != m_font.m_pattern)) {
-        FcPatternDestroy(m_font.m_pattern);
-        m_font.m_pattern = 0;
-    }
-
-    if (m_font.m_fallbacks) {
-        FcFontSetDestroy(m_font.m_fallbacks);
-        m_font.m_fallbacks = 0;
-    }
-
-    if (m_font.m_scaledFont) {
-        cairo_scaled_font_destroy(m_font.m_scaledFont);
-        m_font.m_scaledFont = 0;
-    }
 }
 
 SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDescription) const