1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 22:37:36 +00:00

AK: Fix ref leak in NonnullRefPtr::operator=(T&).

We would leak a ref when assigning a T& to a NonnullRefPtr that already
contains that same T.
This commit is contained in:
Andreas Kling 2019-08-02 11:35:05 +02:00
parent d9cc3e453c
commit 6db879ee66
3 changed files with 44 additions and 4 deletions

View file

@ -131,10 +131,11 @@ public:
NonnullRefPtr& operator=(T& object)
{
if (m_ptr != &object)
if (m_ptr != &object) {
deref_if_not_null(m_ptr);
m_ptr = &object;
m_ptr->ref();
m_ptr = &object;
m_ptr->ref();
}
return *this;
}