Pārlūkot izejas kodu

LibGUI: GWindow's focused widget should be a WeakPtr.

This fixes some very obvious use-after-free accesses.
Andreas Kling 6 gadi atpakaļ
vecāks
revīzija
cc9cefbd5f
2 mainītis faili ar 2 papildinājumiem un 2 dzēšanām
  1. 1 1
      LibGUI/GWindow.cpp
  2. 1 1
      LibGUI/GWindow.h

+ 1 - 1
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();

+ 1 - 1
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;