From: Mikko Rasa Date: Sun, 20 Aug 2023 20:25:02 +0000 (+0300) Subject: Clear saved input focus if the widget is removed from the container X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ab45b7660aec83978871ade009846dcb8c34579f;p=libs%2Fgltk.git Clear saved input focus if the widget is removed from the container Checking the saved focus widget's parent in focus_in can lead to use after free if the widget was deleted in the meantime. --- diff --git a/source/container.cpp b/source/container.cpp index 393973c..9ef46f1 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -35,6 +35,8 @@ void Container::remove(Widget &wdg) if(i==children.end()) throw hierarchy_error("widget not in container"); + if(&wdg==saved_input_focus) + saved_input_focus = nullptr; wdg.set_parent(nullptr); delete *i; children.erase(i); @@ -317,7 +319,7 @@ bool Container::character(wchar_t ch) void Container::focus_in() { - if(saved_input_focus && saved_input_focus->get_parent()==this) + if(saved_input_focus) set_input_focus(saved_input_focus); Widget::focus_in(); }