mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-18 18:11:23 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/09fe9f4542b Pull-request: https://github.com/SerenityOS/serenity/pull/7060 Issue: https://github.com/SerenityOS/serenity/issues/4592
1 changed files with 14 additions and 14 deletions
|
@ -129,22 +129,22 @@ TEST_CASE(assign_copy_self)
|
|||
|
||||
TEST_CASE(self_observers)
|
||||
{
|
||||
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
{
|
||||
RefPtr<SelfAwareObject> object = adopt_ref(*new SelfAwareObject);
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
|
||||
object->ref();
|
||||
EXPECT_EQ(object->ref_count(), 2u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
object->ref();
|
||||
EXPECT_EQ(object->ref_count(), 2u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, false);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
|
||||
object->unref();
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, true);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
|
||||
object->unref();
|
||||
object->unref();
|
||||
EXPECT_EQ(object->ref_count(), 1u);
|
||||
EXPECT_EQ(object->m_has_one_ref_left, true);
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 0u);
|
||||
}
|
||||
EXPECT_EQ(SelfAwareObject::num_destroyed, 1u);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue