[Bf-blender-cvs] [b4a4004fb15] master: Fix memory leak in cryptomatte

Sergey Sharybin noreply at git.blender.org
Mon Apr 25 12:00:55 CEST 2022


Commit: b4a4004fb15fd7952bcd8348f299f6103dea35fb
Author: Sergey Sharybin
Date:   Fri Apr 22 18:27:45 2022 +0200
Branches: master
https://developer.blender.org/rBb4a4004fb15fd7952bcd8348f299f6103dea35fb

Fix memory leak in cryptomatte

Since cbf033c0551 the `matte_id` will be allocated in the node
storage for the forward compatibility purposes. However, this
field was never freed, leading to memory leak.

Causes annoying popup on macOS when running Cycles tests,
for example render_passes_cryptomatte_asset.blend

Differential Revision: https://developer.blender.org/D14728

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

M	source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc

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

diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index 67d861aad9f..9193f91087a 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@ -21,6 +21,8 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 
+#include "MEM_guardedalloc.h"
+
 #include <optional>
 
 /* -------------------------------------------------------------------- */
@@ -249,6 +251,7 @@ static void node_free_cryptomatte(bNode *node)
   NodeCryptomatte *nc = static_cast<NodeCryptomatte *>(node->storage);
 
   if (nc) {
+    MEM_SAFE_FREE(nc->matte_id);
     BLI_freelistN(&nc->runtime.layers);
     BLI_freelistN(&nc->entries);
     MEM_freeN(nc);
@@ -264,6 +267,7 @@ static void node_copy_cryptomatte(bNodeTree *UNUSED(dest_ntree),
 
   BLI_duplicatelist(&dest_nc->entries, &src_nc->entries);
   BLI_listbase_clear(&dest_nc->runtime.layers);
+  dest_nc->matte_id = static_cast<char *>(MEM_dupallocN(src_nc->matte_id));
   dest_node->storage = dest_nc;
 }



More information about the Bf-blender-cvs mailing list