From 577f90feba0a0f88ba0478bac9b10a3724795d4e Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 7 Feb 2025 09:30:02 +0800 Subject: [PATCH] Fix heap-use-after-free when changing 2D editor selection --- editor/plugins/canvas_item_editor_plugin.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index a58659f29b4..7381f2ab83a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3659,10 +3659,12 @@ void CanvasItemEditor::_draw_selection() { } // Remove non-movable nodes. - for (CanvasItem *ci : selection) { - if (!_is_node_movable(ci)) { - selection.erase(ci); + for (List::Element *E = selection.front(); E;) { + List::Element *N = E->next(); + if (!_is_node_movable(E->get())) { + selection.erase(E); } + E = N; } if (!selection.is_empty() && transform_tool && show_transformation_gizmos) {