mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibCore: ObjectPtr should delete the pointee when cleared
We were only deleting the pointee when the ObjectPtr was destroyed. If the ObjectPtr is cleared before that, we should also delete the pointee. This is not the most important class to get right, since it will go away as soon as we're able to switch to RefPtr.
This commit is contained in:
parent
4d8455156e
commit
9e00651e14
Notes:
sideshowbarker
2024-07-19 12:01:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9e00651e144
1 changed files with 17 additions and 1 deletions
|
@ -17,9 +17,21 @@ public:
|
|||
{
|
||||
}
|
||||
~ObjectPtr()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
if (m_ptr && !m_ptr->parent())
|
||||
delete m_ptr;
|
||||
m_ptr = nullptr;
|
||||
}
|
||||
|
||||
ObjectPtr& operator=(std::nullptr_t)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
|
@ -52,13 +64,17 @@ public:
|
|||
|
||||
ObjectPtr& operator=(const ObjectPtr& other)
|
||||
{
|
||||
m_ptr = other.m_ptr;
|
||||
if (this != &other) {
|
||||
clear();
|
||||
m_ptr = other.m_ptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ObjectPtr& operator=(ObjectPtr&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
clear();
|
||||
m_ptr = exchange(other.m_ptr, nullptr);
|
||||
}
|
||||
return *this;
|
||||
|
|
Loading…
Add table
Reference in a new issue