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:
parent
b956691cdd
commit
5d41cee816
@ -30,6 +30,8 @@ public:
|
||||
void GetUnchecked();
|
||||
|
||||
private:
|
||||
friend class BWeakReferenceable;
|
||||
|
||||
int32 fUseCount;
|
||||
BWeakReferenceable* fObject;
|
||||
};
|
||||
|
@ -79,7 +79,10 @@ 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];
|
||||
snprintf(message, sizeof(message), "deleting referenceable object %p with "
|
||||
"reference count (%" B_PRId32 ")", this, fPointer->UseCount());
|
||||
|
Loading…
x
Reference in New Issue
Block a user