From c70e0a4f29421570dea2c048c2501d3c52074091 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 6 Apr 2021 15:50:47 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/TreeNode.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Userland/Libraries/LibWeb/TreeNode.h b/Userland/Libraries/LibWeb/TreeNode.h index 35f9a960e2..c26ec46467 100644 --- a/Userland/Libraries/LibWeb/TreeNode.h +++ b/Userland/Libraries/LibWeb/TreeNode.h @@ -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() { }