From cc9cefbd5f627ca6f0a6c4f4fc9c4d3c8af21239 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 18 Apr 2019 23:16:57 +0200 Subject: [PATCH] LibGUI: GWindow's focused widget should be a WeakPtr. This fixes some very obvious use-after-free accesses. --- LibGUI/GWindow.cpp | 2 +- LibGUI/GWindow.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp index 31f9c33e8f1..de38f0ffcc4 100644 --- a/LibGUI/GWindow.cpp +++ b/LibGUI/GWindow.cpp @@ -337,7 +337,7 @@ void GWindow::set_focused_widget(GWidget* widget) GEventLoop::current().post_event(*m_focused_widget, make(GEvent::FocusOut)); m_focused_widget->update(); } - m_focused_widget = widget; + m_focused_widget = widget ? widget->make_weak_ptr() : nullptr; if (m_focused_widget) { GEventLoop::current().post_event(*m_focused_widget, make(GEvent::FocusIn)); m_focused_widget->update(); diff --git a/LibGUI/GWindow.h b/LibGUI/GWindow.h index 9aa9c411127..e276ea6dbb8 100644 --- a/LibGUI/GWindow.h +++ b/LibGUI/GWindow.h @@ -120,7 +120,7 @@ private: int m_window_id { 0 }; float m_opacity_when_windowless { 1.0f }; GWidget* m_main_widget { nullptr }; - GWidget* m_focused_widget { nullptr }; + WeakPtr m_focused_widget; WeakPtr m_global_cursor_tracking_widget; WeakPtr m_automatic_cursor_tracking_widget; WeakPtr m_hovered_widget;