1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

SafePointer: Avoid potential double-deletes

deleteAndZero now behaves more like unique_ptr::reset, which sets the
new stored value before freeing the old one.
This commit is contained in:
reuk 2024-05-01 17:54:08 +01:00
parent 5d2b1b7aa7
commit aeeb06ccb9
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -2344,7 +2344,7 @@ public:
ComponentType* operator->() const noexcept { return getComponent(); }
/** If the component is valid, this deletes it and sets this pointer to null. */
void deleteAndZero() { delete getComponent(); }
void deleteAndZero() { delete std::exchange (weakRef, nullptr); }
bool operator== (ComponentType* component) const noexcept { return weakRef == component; }
bool operator!= (ComponentType* component) const noexcept { return weakRef != component; }