Commit: d4efcef5e303eae1be9c6d7e1dc17f72a9a71252
Author: Omar Emara
Date:   Thu Apr 7 12:23:25 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rBd4efcef5e303eae1be9c6d7e1dc17f72a9a71252

Viewport Compositor: Fix use after free results

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

M       source/blender/nodes/NOD_compositor_execute.hh
M       source/blender/nodes/intern/node_compositor_execute.cc

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

diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index 4463db979cc..5c0591db5bc 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -4,6 +4,7 @@
 #pragma once
 
 #include <cstdint>
+#include <memory>
 
 #include "BLI_map.hh"
 #include "BLI_math_vec_types.hh"
@@ -567,8 +568,8 @@ class NodeOperation : public Operation {
  private:
   /* The node that this operation represents. */
   DNode node_;
-  /* A vector storing the results mapped to the inputs that are not linked. */
-  Vector<Result> unlinked_inputs_results_;
+  /* A vector storing unique pointers to the results mapped to unlinked 
inputs. */
+  Vector<std::unique_ptr<Result>> unlinked_inputs_results_;
   /* A mapping between each unlinked input in the node identified by its 
identifier and its
    * corresponding input socket. */
   Map<StringRef, DInputSocket> unlinked_inputs_sockets_;
diff --git a/source/blender/nodes/intern/node_compositor_execute.cc 
b/source/blender/nodes/intern/node_compositor_execute.cc
index 3d1cb671486..ecd3d807098 100644
--- a/source/blender/nodes/intern/node_compositor_execute.cc
+++ b/source/blender/nodes/intern/node_compositor_execute.cc
@@ -2,6 +2,7 @@
  * Copyright 2022 Blender Foundation. All rights reserved. */
 
 #include <limits>
+#include <memory>
 #include <string>
 
 #include "BLI_assert.h"
@@ -697,9 +698,8 @@ void NodeOperation::populate_results_for_unlinked_inputs()
     /* Construct a result of an appropriate type, add it to the results 
vector, and map the input
      * to it. */
     const ResultType result_type = 
get_node_socket_result_type(origin.socket_ref());
-    const Result result = Result(result_type, texture_pool());
-    unlinked_inputs_results_.append(result);
-    map_input_to_result(input->identifier(), &unlinked_inputs_results_.last());
+    unlinked_inputs_results_.append(std::make_unique<Result>(result_type, 
texture_pool()));
+    map_input_to_result(input->identifier(), 
unlinked_inputs_results_.last().get());
 
     /* Map the input to the socket to later allocate and initialize its value. 
*/
     const DInputSocket origin_input{origin.context(), &origin->as_input()};

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to