mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-21 18:42:53 +00:00
LibHTML: Have TreeNode deref its children before deleting itself
This is definitely not the ideal ownership model here, but it's something we'll have to iterate on as the engine grows. At least this prevents us from leaking the entire world. :^)
This commit is contained in:
parent
c458327429
commit
796e63b34c
Notes:
sideshowbarker
2024-07-19 11:44:28 +09:00
Author: https://github.com/awesomekling
Commit: 796e63b34c
1 changed files with 12 additions and 1 deletions
|
@ -15,8 +15,19 @@ public:
|
|||
void deref()
|
||||
{
|
||||
ASSERT(m_ref_count);
|
||||
if (!--m_ref_count)
|
||||
if (!--m_ref_count) {
|
||||
if (m_next_sibling)
|
||||
m_next_sibling->m_previous_sibling = m_previous_sibling;
|
||||
if (m_previous_sibling)
|
||||
m_previous_sibling->m_next_sibling = m_next_sibling;
|
||||
T* next_child;
|
||||
for (auto* child = m_first_child; child; child = next_child) {
|
||||
next_child = child->m_next_sibling;
|
||||
child->m_parent = nullptr;
|
||||
child->deref();
|
||||
}
|
||||
delete static_cast<T*>(this);
|
||||
}
|
||||
}
|
||||
int ref_count() const { return m_ref_count; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue