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

Changeset 249198 in webkit


Ignore:
Timestamp:
Aug 28, 2019, 8:15:51 AM (7 years ago)
Author:
rniwa@webkit.org
Message:

REGRESSION (r248807): Objects stored in ElementRareData are leaked
https://bugs.webkit.org/show_bug.cgi?id=200954

Reviewed by Antti Koivisto.

Use a custom deleter in std::unique_ptr to call the correct destructor instead of making
NodeRareData's destructor virtual. Added NodeRareData::isElementRareData to differentiate
ElementRareData and NodeRareData by borrowing 1 bit from the frame count.

No new tests since there should be no behavioral change.

  • dom/ElementRareData.h:

(WebCore::ElementRareData::ElementRareData):

  • dom/Node.cpp:

(WebCore::Node::materializeRareData): Call the constructors of unique_ptr directly since
make_unique does not take a custom deleter. We can't add the support to makeUnique either
without making it three arguments since we need to cast ElementRareData to NodeRareData
in addition to specifying a custom deleter (normal casting wouldn't work due to
the presence of a custom deleter).
(WebCore::Node::NodeRareDataDeleter::operator() const): Added.

  • dom/Node.h:

(WebCore::Node::NodeRareDataDeleter): Added.

  • dom/NodeRareData.cpp:
  • dom/NodeRareData.h:

(WebCore::NodeRareData::NodeRareData): Makes newly added Type.
(WebCore::NodeRareData::isElementRareData): Added.
(WebCore::NodeRareData::~NodeRareData): Deleted.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249197 r249198  
     12019-08-28  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        REGRESSION (r248807): Objects stored in ElementRareData are leaked
     4        https://bugs.webkit.org/show_bug.cgi?id=200954
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Use a custom deleter in std::unique_ptr to call the correct destructor instead of making
     9        NodeRareData's destructor virtual. Added NodeRareData::isElementRareData to differentiate
     10        ElementRareData and NodeRareData by borrowing 1 bit from the frame count.
     11
     12        No new tests since there should be no behavioral change.
     13
     14        * dom/ElementRareData.h:
     15        (WebCore::ElementRareData::ElementRareData):
     16        * dom/Node.cpp:
     17        (WebCore::Node::materializeRareData): Call the constructors of unique_ptr directly since
     18        make_unique does not take a custom deleter. We can't add the support to makeUnique either
     19        without making it three arguments since we need to cast ElementRareData to NodeRareData
     20        in addition to specifying a custom deleter (normal casting wouldn't work due to
     21        the presence of a custom deleter).
     22        (WebCore::Node::NodeRareDataDeleter::operator() const): Added.
     23        * dom/Node.h:
     24        (WebCore::Node::NodeRareDataDeleter): Added.
     25        * dom/NodeRareData.cpp:
     26        * dom/NodeRareData.h:
     27        (WebCore::NodeRareData::NodeRareData): Makes newly added Type.
     28        (WebCore::NodeRareData::isElementRareData): Added.
     29        (WebCore::NodeRareData::~NodeRareData): Deleted.
     30
    1312019-08-28  Claudio Saavedra  <csaavedra@igalia.com>
    232
  • trunk/Source/WebCore/dom/ElementRareData.h

    r248807 r249198  
    191191
    192192inline ElementRareData::ElementRareData()
    193     : m_tabIndex(0)
     193    : NodeRareData(Type::Element)
     194    , m_tabIndex(0)
    194195    , m_childIndex(0)
    195196    , m_tabIndexWasSetExplicitly(false)
  • trunk/Source/WebCore/dom/Node.cpp

    r248846 r249198  
    396396{
    397397    if (is<Element>(*this))
    398         m_rareData = makeUnique<ElementRareData>();
     398        m_rareData = std::unique_ptr<NodeRareData, NodeRareDataDeleter>(new ElementRareData);
    399399    else
    400         m_rareData = makeUnique<NodeRareData>();
     400        m_rareData = std::unique_ptr<NodeRareData, NodeRareDataDeleter>(new NodeRareData);
     401}
     402
     403inline void Node::NodeRareDataDeleter::operator()(NodeRareData* rareData) const
     404{
     405    if (rareData->isElementRareData())
     406        delete static_cast<ElementRareData*>(rareData);
     407    else
     408        delete static_cast<NodeRareData*>(rareData);
    401409}
    402410
  • trunk/Source/WebCore/dom/Node.h

    r248807 r249198  
    665665    void moveNodeToNewDocument(Document& oldDocument, Document& newDocument);
    666666
     667    struct NodeRareDataDeleter {
     668        void operator()(NodeRareData*) const;
     669    };
     670
    667671    uint32_t m_refCountAndParentBit { s_refCountIncrement };
    668672    mutable uint32_t m_nodeFlags;
     
    673677    Node* m_next { nullptr };
    674678    CompactPointerTuple<RenderObject*, uint8_t> m_rendererWithStyleFlags;
    675     std::unique_ptr<NodeRareData> m_rareData;
     679    std::unique_ptr<NodeRareData, NodeRareDataDeleter> m_rareData;
    676680};
    677681
  • trunk/Source/WebCore/dom/NodeRareData.cpp

    r249076 r249198  
    3737
    3838struct SameSizeAsNodeRareData {
    39     unsigned m_frameCount;
    40     void* m_pointer[3];
     39    unsigned m_frameCountAndIsElementRareDataFlag;
     40    void* m_pointer[2];
    4141};
    4242
  • trunk/Source/WebCore/dom/NodeRareData.h

    r249076 r249198  
    271271#endif
    272272
    273     NodeRareData()
    274     { }
    275 
    276     virtual ~NodeRareData()
    277     { }
     273    enum class Type { Element, Node };
     274
     275    NodeRareData(Type type = Type::Node)
     276        : m_connectedFrameCount(0)
     277        , m_isElementRareData(type == Type::Element)
     278    {
     279    }
     280
     281    bool isElementRareData() { return m_isElementRareData; }
    278282
    279283    void clearNodeLists() { m_nodeLists = nullptr; }
     
    321325
    322326private:
    323     unsigned m_connectedFrameCount { 0 }; // Must fit Page::maxNumberOfFrames.
     327    unsigned m_connectedFrameCount : 31; // Must fit Page::maxNumberOfFrames.
     328    unsigned m_isElementRareData : 1;
    324329
    325330    std::unique_ptr<NodeListsNodeData> m_nodeLists;
Note: See TracChangeset for help on using the changeset viewer.