From 4e4daa641764fcd5fe54edb98d3e4bec47480992 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Wed, 14 Sep 2022 08:42:57 -0300 Subject: Fix T100959: Memory leak when moving node with Alt The memory leak happens because `ED_node_link_insert` (called after the transform operation) overwrites the pre-existing `snode->runtime->iofsd`, losing the reference without freeing the memory. So to "move" the reference from `snode->runtime->iofsd` to `op->customdata`, so that each operator works with its own data. Reviewed By: Severin Differential Revision: https://developer.blender.org/D15948 --- source/blender/editors/space_node/node_relationships.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 929fb64bd70..e12ab3191cb 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -2312,10 +2312,10 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, /** * Modal handler for insert offset animation */ -static int node_insert_offset_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int node_insert_offset_modal(bContext *C, wmOperator *op, const wmEvent *event) { SpaceNode *snode = CTX_wm_space_node(C); - NodeInsertOfsData *iofsd = snode->runtime->iofsd; + NodeInsertOfsData *iofsd = static_cast(op->customdata); bool redraw = false; if (!snode || event->type != TIMER || iofsd == nullptr || @@ -2355,7 +2355,6 @@ static int node_insert_offset_modal(bContext *C, wmOperator *UNUSED(op), const w node->anim_init_locx = node->anim_ofsx = 0.0f; } - snode->runtime->iofsd = nullptr; MEM_freeN(iofsd); return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH); @@ -2370,6 +2369,8 @@ static int node_insert_offset_invoke(bContext *C, wmOperator *op, const wmEvent { const SpaceNode *snode = CTX_wm_space_node(C); NodeInsertOfsData *iofsd = snode->runtime->iofsd; + snode->runtime->iofsd = nullptr; + op->customdata = iofsd; if (!iofsd || !iofsd->insert) { return OPERATOR_CANCELLED; @@ -2476,6 +2477,7 @@ void ED_node_link_insert(Main *bmain, ScrArea *area) /* Set up insert offset data, it needs stuff from here. */ if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { + BLI_assert(snode->runtime->iofsd == nullptr); NodeInsertOfsData *iofsd = MEM_cnew(__func__); iofsd->insert = node_to_insert; -- cgit v1.2.3