From aeeb06ccb9bb846aaee54737bbca0e8d7855ffbd Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 1 May 2024 17:54:08 +0100 Subject: [PATCH] SafePointer: Avoid potential double-deletes deleteAndZero now behaves more like unique_ptr::reset, which sets the new stored value before freeing the old one. --- modules/juce_gui_basics/components/juce_Component.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index dbc47b034d..bd66292a1b 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -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; }