[CSS OM] StyledElementInlineStylePropertyMap creates a Ref cycle with its owner element
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 21:23:02 +0000 (21:23 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 21:23:02 +0000 (21:23 +0000)
commit7fd40144e03369b181dac6e8e10a1304a58f5948
tree0f81648e7b907be40b3cc56ac49960a9fa776be5
parentcfca1764458de8add8e9cef2ad1e94402b4896da
[CSS OM] StyledElementInlineStylePropertyMap creates a Ref cycle with its owner element
https://bugs.webkit.org/show_bug.cgi?id=195987

Reviewed by Simon Fraser.

Source/WebCore:

StyledElementInlineStylePropertyMap was leaking every element for which it was created because due to
a reference cycle. The StyledElementInlineStylePropertyMap holds onto its element using Ref and
the element also stores StyledElementInlineStylePropertyMap in ElementRareData using RefPtr.

Fixed the cycle by making the reference from StyledElementInlineStylePropertyMap weak. For now we use
a raw pointer because we can't create a WeakPtr of an element yet.

Test: css-typedom/attribute-style-map-should-not-leak-every-element.html

* css/typedom/StylePropertyMap.h:
(WebCore::StylePropertyMap): Added clearElement as a virtual function.
* dom/Element.cpp:
(WebCore::Element::~Element): Clear the element pointer in StyledElementInlineStylePropertyMap.
* dom/StyledElement.cpp:
(WebCore::StyledElementInlineStylePropertyMap::get): Added a null check for m_element.
(WebCore::StyledElementInlineStylePropertyMap::StyledElementInlineStylePropertyMap):
(WebCore::StyledElementInlineStylePropertyMap::clearElement): Added.
(WebCore::StyledElementInlineStylePropertyMap): Use a raw pointer instead of Ref to StyledElement
to avoid the leak.
* platform/graphics/CustomPaintImage.cpp:
(WebCore::HashMapStylePropertyMap::clearElement): Added.

LayoutTests:

Added a regression test.

* css-typedom/attribute-style-map-should-not-leak-every-element-expected.txt: Added.
* css-typedom/attribute-style-map-should-not-leak-every-element.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243239 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/css-typedom/attribute-style-map-should-not-leak-every-element-expected.txt [new file with mode: 0644]
LayoutTests/css-typedom/attribute-style-map-should-not-leak-every-element.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/typedom/StylePropertyMap.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/platform/graphics/CustomPaintImage.cpp