diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-18 23:16:57 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-18 23:16:57 +0200 |
commit | cc9cefbd5f627ca6f0a6c4f4fc9c4d3c8af21239 (patch) | |
tree | e9c49c93d669ef0bd9ad940194b5e5bc91039e9e | |
parent | 9e6b0ccc0e1d5f830b82ae719a689d0605e0f607 (diff) | |
download | serenity-cc9cefbd5f627ca6f0a6c4f4fc9c4d3c8af21239.zip |
LibGUI: GWindow's focused widget should be a WeakPtr.
This fixes some very obvious use-after-free accesses.
-rw-r--r-- | LibGUI/GWindow.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GWindow.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp index 31f9c33e8f..de38f0ffcc 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>(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>(GEvent::FocusIn)); m_focused_widget->update(); diff --git a/LibGUI/GWindow.h b/LibGUI/GWindow.h index 9aa9c41112..e276ea6dbb 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<GWidget> m_focused_widget; WeakPtr<GWidget> m_global_cursor_tracking_widget; WeakPtr<GWidget> m_automatic_cursor_tracking_widget; WeakPtr<GWidget> m_hovered_widget; |