summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/Button.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-14 19:37:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-14 20:43:42 +0100
commitb00a347ac5a5f88057d787ef3feb8c109efac4d9 (patch)
tree989114cc051df7725533ce01f551009c1436d78a /Libraries/LibGUI/Button.cpp
parentdd2e8b7dd008d0176225b838b9ff83a4996eab81 (diff)
downloadserenity-b00a347ac5a5f88057d787ef3feb8c109efac4d9.zip
LibGUI: Protect GUI::Button across firing the on_click hook
If a hook triggers the deletion of the GUI::Button, we would be unable to proceed in a well-defined manner here, so let's protect ourselves. This probably needs to be done in a whole lot of places, since GUI widgets are just ref-counted Core::Objects and running arbitrary code can mean that they get deleted.
Diffstat (limited to 'Libraries/LibGUI/Button.cpp')
-rw-r--r--Libraries/LibGUI/Button.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp
index f488c272b8..1aeb419a0b 100644
--- a/Libraries/LibGUI/Button.cpp
+++ b/Libraries/LibGUI/Button.cpp
@@ -108,6 +108,9 @@ void Button::click(unsigned modifiers)
{
if (!is_enabled())
return;
+
+ NonnullRefPtr protector = *this;
+
if (is_checkable()) {
if (is_checked() && !is_uncheckable())
return;