WeakReferenceable: Clear fUseCount when it is 1.
Otherwise, if there are remaining weak references, they could potentially try to acquire the object and trigger a use-after-free.
This commit is contained in:
@@ -30,6 +30,8 @@ public:
|
|||||||
void GetUnchecked();
|
void GetUnchecked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class BWeakReferenceable;
|
||||||
|
|
||||||
int32 fUseCount;
|
int32 fUseCount;
|
||||||
BWeakReferenceable* fObject;
|
BWeakReferenceable* fObject;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ BWeakReferenceable::BWeakReferenceable()
|
|||||||
|
|
||||||
BWeakReferenceable::~BWeakReferenceable()
|
BWeakReferenceable::~BWeakReferenceable()
|
||||||
{
|
{
|
||||||
if (fPointer->UseCount() != 0 && fPointer->UseCount() != 1) {
|
if (fPointer->UseCount() == 1)
|
||||||
|
atomic_test_and_set(&fPointer->fUseCount, 0, 1);
|
||||||
|
|
||||||
|
if (fPointer->UseCount() != 0) {
|
||||||
char message[256];
|
char message[256];
|
||||||
snprintf(message, sizeof(message), "deleting referenceable object %p with "
|
snprintf(message, sizeof(message), "deleting referenceable object %p with "
|
||||||
"reference count (%" B_PRId32 ")", this, fPointer->UseCount());
|
"reference count (%" B_PRId32 ")", this, fPointer->UseCount());
|
||||||
|
|||||||
Reference in New Issue
Block a user