mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
AK: Assert if trying to create a WeakPtr to an object being destroyed
Trying to make_weak_ptr() on something that has begun destruction is very unlikely to be what you want. Let's assert if that scenario comes up so we can catch it immediately.
This commit is contained in:
parent
b0192cfb38
commit
3f52cee595
Notes:
sideshowbarker
2024-07-19 09:50:42 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3f52cee5955
@ -88,6 +88,9 @@ private:
|
||||
template<typename T>
|
||||
inline WeakPtr<T> Weakable<T>::make_weak_ptr()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
ASSERT(!m_being_destroyed);
|
||||
#endif
|
||||
if (!m_link)
|
||||
m_link = adopt(*new WeakLink<T>(static_cast<T&>(*this)));
|
||||
return WeakPtr<T>(m_link);
|
||||
|
@ -27,8 +27,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Assertions.h"
|
||||
#include "RefPtr.h"
|
||||
#include "RefCounted.h"
|
||||
#include "RefPtr.h"
|
||||
|
||||
namespace AK {
|
||||
|
||||
@ -66,12 +66,18 @@ protected:
|
||||
|
||||
~Weakable()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
m_being_destroyed = true;
|
||||
#endif
|
||||
if (m_link)
|
||||
m_link->m_ptr = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<WeakLink<T>> m_link;
|
||||
#ifdef DEBUG
|
||||
bool m_being_destroyed { false };
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user