⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243483 in webkit


Ignore:
Timestamp:
Mar 25, 2019, 8:34:43 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Leak of SVGFontFaceElement when RenderStyle holds onto a FontRances which uses it
https://bugs.webkit.org/show_bug.cgi?id=196059

Reviewed by Zalan Bujtas.

SVGFontFaceElement keeps its RenderStyle alive via ElementRareData but RenderStyle can hold onto FontRanges
and therefore CSSFontSource, which in turn keeps SVGFontFaceElement alive, making a reference cycle.

More precisely, there are two reference cycles:
SVGFontFaceElement (1) -> ElementRareData -> StyleInheritedData -> FontCascade -> FontCascadeFonts (2)
FontCascadeFonts (2) -> FontRanges (3)
FontCascadeFonts (2) -> CSSFontSelector -> CSSFontFaceSet -> CSSSegmentedFontFace -> FontRanges (3)
FontRanges (3) -> CSSFontAccessor > CSSFontFace > CSSFontSource -> SVGFontFaceElement (1)

No new tests. Unfortunately, writing a test proved to be intractable. The leak can be reproduced by running
svg/text/text-text-05-t.svg then svg/zoom/page/zoom-img-preserveAspectRatio-support-1.html consecutively.

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::CSSFontFaceSource):
(WebCore::CSSFontFaceSource::load):
(WebCore::CSSFontFaceSource::font):
(WebCore::CSSFontFaceSource::isSVGFontFaceSource const):

  • css/CSSFontFaceSource.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243482 r243483  
     12019-03-20  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Leak of SVGFontFaceElement when RenderStyle holds onto a FontRances which uses it
     4        https://bugs.webkit.org/show_bug.cgi?id=196059
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        SVGFontFaceElement keeps its RenderStyle alive via ElementRareData but RenderStyle can hold onto FontRanges
     9        and therefore CSSFontSource, which in turn keeps SVGFontFaceElement alive, making a reference cycle.
     10
     11        More precisely, there are two reference cycles:
     12        SVGFontFaceElement (1) -> ElementRareData -> StyleInheritedData -> FontCascade -> FontCascadeFonts (2)
     13        FontCascadeFonts (2) -> FontRanges (3)
     14        FontCascadeFonts (2) -> CSSFontSelector -> CSSFontFaceSet -> CSSSegmentedFontFace -> FontRanges (3)
     15        FontRanges (3) -> CSSFontAccessor > CSSFontFace > CSSFontSource -> SVGFontFaceElement (1)
     16
     17        No new tests. Unfortunately, writing a test proved to be intractable. The leak can be reproduced by running
     18        svg/text/text-text-05-t.svg then svg/zoom/page/zoom-img-preserveAspectRatio-support-1.html consecutively.
     19
     20        * css/CSSFontFaceSource.cpp:
     21        (WebCore::CSSFontFaceSource::CSSFontFaceSource):
     22        (WebCore::CSSFontFaceSource::load):
     23        (WebCore::CSSFontFaceSource::font):
     24        (WebCore::CSSFontFaceSource::isSVGFontFaceSource const):
     25        * css/CSSFontFaceSource.h:
     26
    1272019-03-25  Fujii Hironori  <Hironori.Fujii@sony.com>
    228
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r239535 r243483  
    8080    , m_immediateSource(WTFMove(arrayBufferView))
    8181#if ENABLE(SVG_FONTS)
    82     , m_svgFontFaceElement(fontFace)
     82    , m_svgFontFaceElement(makeWeakPtr(fontFace))
     83    , m_hasSVGFontFaceElement(m_svgFontFaceElement)
    8384#endif
    8485{
     
    155156        bool success = false;
    156157#if ENABLE(SVG_FONTS)
    157         if (m_svgFontFaceElement) {
    158             if (is<SVGFontElement>(m_svgFontFaceElement->parentNode())) {
     158        if (m_hasSVGFontFaceElement) {
     159            if (m_svgFontFaceElement && is<SVGFontElement>(m_svgFontFaceElement->parentNode())) {
    159160                ASSERT(!m_inDocumentCustomPlatformData);
    160161                SVGFontElement& fontElement = downcast<SVGFontElement>(*m_svgFontFaceElement->parentNode());
     
    196197    ASSERT(status() == Status::Success);
    197198
    198     SVGFontFaceElement* fontFaceElement = nullptr;
    199 #if ENABLE(SVG_FONTS)
    200     fontFaceElement = m_svgFontFaceElement.get();
    201 #endif
    202 
    203     if (!m_font && !fontFaceElement) {
     199#if ENABLE(SVG_FONTS)
     200    bool usesInDocumentSVGFont = m_hasSVGFontFaceElement;
     201#endif
     202
     203    if (!m_font && !usesInDocumentSVGFont) {
    204204        if (m_immediateSource) {
    205205            if (!m_immediateFontCustomPlatformData)
     
    223223    }
    224224
    225     // In-Document SVG Fonts
    226     if (!fontFaceElement)
     225    if (!usesInDocumentSVGFont)
    227226        return nullptr;
    228227
    229228#if ENABLE(SVG_FONTS)
    230     if (!is<SVGFontElement>(m_svgFontFaceElement->parentNode()))
     229    if (!m_svgFontFaceElement || !is<SVGFontElement>(m_svgFontFaceElement->parentNode()))
    231230        return nullptr;
    232231    if (!m_inDocumentCustomPlatformData)
     
    242241bool CSSFontFaceSource::isSVGFontFaceSource() const
    243242{
    244     return m_svgFontFaceElement || is<CachedSVGFont>(m_font.get());
    245 }
    246 #endif
    247 
    248 }
     243    return m_hasSVGFontFaceElement || is<CachedSVGFont>(m_font.get());
     244}
     245#endif
     246
     247}
  • trunk/Source/WebCore/css/CSSFontFaceSource.h

    r228218 r243483  
    9494
    9595#if ENABLE(SVG_FONTS)
    96     RefPtr<SVGFontFaceElement> m_svgFontFaceElement;
     96    WeakPtr<SVGFontFaceElement> m_svgFontFaceElement;
    9797#endif
    9898    std::unique_ptr<FontCustomPlatformData> m_inDocumentCustomPlatformData;
    9999
    100100    Status m_status { Status::Pending };
     101#if ENABLE(SVG_FONTS)
     102    bool m_hasSVGFontFaceElement;
     103#endif
    101104};
    102105
Note: See TracChangeset for help on using the changeset viewer.