AK: Avoid clearing pointer wrappers during destruction

Delete or unref directly from RefPtr, NonnullRefPtr, and NonnullOwnPtr
destructors instead of calling clear() or exchanging the member pointer.
This avoids storing null when the wrapper lifetime is ending.
This commit is contained in:
Andreas Kling 2026-06-13 20:17:02 +02:00 committed by Andreas Kling
parent ccc578e0c0
commit 2a0bc6a6e0
3 changed files with 3 additions and 4 deletions

View file

@ -47,7 +47,7 @@ public:
}
~NonnullOwnPtr()
{
clear();
delete m_ptr;
#ifdef SANITIZE_PTRS
m_ptr = (T*)(explode_byte(NONNULLOWNPTR_SCRUB_BYTE));
#endif

View file

@ -93,8 +93,7 @@ public:
ALWAYS_INLINE ~NonnullRefPtr()
{
auto* ptr = exchange(m_ptr, nullptr);
unref_if_not_null(ptr);
unref_if_not_null(m_ptr);
#ifdef SANITIZE_PTRS
m_ptr = reinterpret_cast<T*>(explode_byte(NONNULLREFPTR_SCRUB_BYTE));
#endif

View file

@ -100,7 +100,7 @@ public:
ALWAYS_INLINE ~RefPtr()
{
clear();
unref_if_not_null(m_ptr);
#ifdef SANITIZE_PTRS
m_ptr = reinterpret_cast<T*>(explode_byte(REFPTR_SCRUB_BYTE));
#endif