From b00a347ac5a5f88057d787ef3feb8c109efac4d9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 14 Dec 2020 19:37:55 +0100 Subject: [PATCH] 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. --- Libraries/LibGUI/Button.cpp | 3 +++ 1 file changed, 3 insertions(+) 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;