LibWeb: Sever parent/child connections in ~TreeNode()

Also make sure to unref the children if there are any. Without this
it was very easy to leak TreeNodes.
This commit is contained in:
Andreas Kling 2021-04-06 15:50:47 +02:00
parent 41e5a0fe02
commit c70e0a4f29
Notes: sideshowbarker 2024-07-18 20:43:50 +09:00

View File

@ -299,6 +299,17 @@ public:
return nullptr;
}
~TreeNode()
{
VERIFY(!m_parent);
T* next_child = nullptr;
for (auto* child = m_first_child; child; child = next_child) {
next_child = child->m_next_sibling;
child->m_parent = nullptr;
child->unref();
}
}
protected:
TreeNode() { }