[Bf-blender-cvs] [3ba1c11f3b6] functions-experimental-refactor: fix memory leak

Jacques Lucke noreply at git.blender.org
Thu Oct 31 15:02:05 CET 2019


Commit: 3ba1c11f3b6589ef71aafb4d2470e006617701ff
Author: Jacques Lucke
Date:   Thu Oct 31 15:01:53 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB3ba1c11f3b6589ef71aafb4d2470e006617701ff

fix memory leak

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

M	source/blender/blenkernel/BKE_generic_array_ref.h
M	source/blender/modifiers/intern/MOD_functiondeform_cxx.cc

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

diff --git a/source/blender/blenkernel/BKE_generic_array_ref.h b/source/blender/blenkernel/BKE_generic_array_ref.h
index 408f05738a3..d5ebe17516c 100644
--- a/source/blender/blenkernel/BKE_generic_array_ref.h
+++ b/source/blender/blenkernel/BKE_generic_array_ref.h
@@ -96,6 +96,16 @@ class GenericMutableArrayRef {
     }
   }
 
+  void destruct_indices(ArrayRef<uint> indices)
+  {
+    if (m_type->trivially_destructible()) {
+      return;
+    }
+    for (uint i : indices) {
+      m_type->destruct((*this)[i]);
+    }
+  }
+
   const CPPType &type() const
   {
     return *m_type;
diff --git a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
index e2d3554a54d..ed10a50c0af 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
+++ b/source/blender/modifiers/intern/MOD_functiondeform_cxx.cc
@@ -882,6 +882,7 @@ class MultiFunction_FunctionTree : public BKE::MultiFunction {
 
   class Storage {
    private:
+    ArrayRef<uint> m_mask_indices;
     Vector<GenericVectorArray *> m_vector_arrays;
     Vector<GenericMutableArrayRef> m_arrays;
     Map<uint, GenericVectorArray *> m_vector_per_socket;
@@ -889,15 +890,17 @@ class MultiFunction_FunctionTree : public BKE::MultiFunction {
     Map<uint, GenericVirtualListListRef> m_virtual_list_list_for_inputs;
 
    public:
-    Storage() = default;
+    Storage(ArrayRef<uint> mask_indices) : m_mask_indices(mask_indices)
+    {
+    }
 
     ~Storage()
     {
       for (GenericVectorArray *vector_array : m_vector_arrays) {
         delete vector_array;
       }
-      /* TODO: Proper freeing of elements in array. */
       for (GenericMutableArrayRef array : m_arrays) {
+        array.destruct_indices(m_mask_indices);
         MEM_freeN(array.buffer());
       }
     }
@@ -974,7 +977,7 @@ class MultiFunction_FunctionTree : public BKE::MultiFunction {
       return;
     }
 
-    Storage storage;
+    Storage storage(mask_indices);
     this->copy_inputs_to_storage(params, storage);
     this->evaluate_network_to_compute_outputs(mask_indices, context, storage);
     this->copy_computed_values_to_outputs(mask_indices, params, storage);



More information about the Bf-blender-cvs mailing list