summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/SpinBox.cpp
diff options
context:
space:
mode:
authorAndrew Smith <andrew@alsmith.net>2022-03-08 01:41:09 -0600
committerAndreas Kling <kling@serenityos.org>2022-03-08 22:18:59 +0100
commit31a2ac94c75a32877a2f63ba8c30e6a43116fd73 (patch)
treed3f0081fdeaf6c13a68a2530957f67a17bfcc313 /Userland/Libraries/LibGUI/SpinBox.cpp
parent9246ad96b393dff5d3e3cd8feec1a6148d45408b (diff)
downloadserenity-31a2ac94c75a32877a2f63ba8c30e6a43116fd73.zip
LibGUI: Fix crash in GML Playground auto-completing SpinBox props
Crash was caused by deferred invocation of a lambda on the SpinBox's TextEditor widget's on_change. The lambda referenced the SpinBox ptr, but in GML Playground the SpinBox was free'd before the deferred lambda could run, causing a use-after-free error. Fixed by using a weak ptr to detect if the SpinBox was free'd.
Diffstat (limited to 'Userland/Libraries/LibGUI/SpinBox.cpp')
-rw-r--r--Userland/Libraries/LibGUI/SpinBox.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/SpinBox.cpp b/Userland/Libraries/LibGUI/SpinBox.cpp
index ad988d4681..e46278376b 100644
--- a/Userland/Libraries/LibGUI/SpinBox.cpp
+++ b/Userland/Libraries/LibGUI/SpinBox.cpp
@@ -18,7 +18,10 @@ SpinBox::SpinBox()
set_fixed_height(22);
m_editor = add<TextBox>();
m_editor->set_text("0");
- m_editor->on_change = [this] {
+ m_editor->on_change = [this, weak_this = make_weak_ptr()] {
+ if (!weak_this)
+ return;
+
auto value = m_editor->text().to_uint();
if (value.has_value())
set_value(value.value());