Fix memory leak in cryptomatte

Since cbf033c055 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
This commit is contained in:
Sergey Sharybin 2022-04-22 18:27:45 +02:00
parent a2d32960b4
commit b4a4004fb1
1 changed files with 4 additions and 0 deletions

View File

@ -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;
}