mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
Tests: Fix use-after-free in TestRefPtr.self_observers
We can't unref an object to destruction while there's still a live RefPtr to the object, otherwise the RefPtr destructor will try to destroy it again, accessing the refcount of a destroyed object (before realizing that oops! the object is already dead)
This commit is contained in:
parent
28987d1b56
commit
09fe9f4542
1 changed files with 14 additions and 14 deletions
|
@ -129,22 +129,22 @@ TEST_CASE(assign_copy_self)
|
||||||
|
|
||||||
TEST_CASE(self_observers)
|
TEST_CASE(self_observers)
|
||||||
{
|
{
|
||||||
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
{
|
||||||
EXPECT_EQ(object->ref_count(), 1u);
|
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
EXPECT_EQ(object->ref_count(), 1u);
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||||
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
|
|
||||||
object->ref();
|
object->ref();
|
||||||
EXPECT_EQ(object->ref_count(), 2u);
|
EXPECT_EQ(object->ref_count(), 2u);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
|
|
||||||
object->unref();
|
object->unref();
|
||||||
EXPECT_EQ(object->ref_count(), 1u);
|
EXPECT_EQ(object->ref_count(), 1u);
|
||||||
EXPECT_EQ(object->m_has_one_ref_left, true);
|
EXPECT_EQ(object->m_has_one_ref_left, true);
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||||
|
}
|
||||||
object->unref();
|
|
||||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 1u);
|
EXPECT_EQ(SelfAwareObject::num_destroyed, 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue