[Bf-blender-cvs] [4e4daa64176] master: Fix T100959: Memory leak when moving node with Alt

Germano Cavalcante noreply at git.blender.org
Wed Sep 14 14:13:43 CEST 2022


Commit: 4e4daa641764fcd5fe54edb98d3e4bec47480992
Author: Germano Cavalcante
Date:   Wed Sep 14 08:42:57 2022 -0300
Branches: master
https://developer.blender.org/rB4e4daa641764fcd5fe54edb98d3e4bec47480992

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

===================================================================

M	source/blender/editors/space_node/node_relationships.cc

===================================================================

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<NodeInsertOfsData *>(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<NodeInsertOfsData>(__func__);
 
     iofsd->insert = node_to_insert;



More information about the Bf-blender-cvs mailing list