Commit: 08530c7eea4958dfc42f89ab818798acfad96fd7
Author: Lukas Tönne
Date:   Thu Dec 31 14:56:54 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB08530c7eea4958dfc42f89ab818798acfad96fd7

Fix memleaks in refcounted data pointers on the bvm stack.

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

M       source/blender/blenvm/intern/bvm_api.cc
M       source/blender/blenvm/util/bvm_util_typedesc.h

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

diff --git a/source/blender/blenvm/intern/bvm_api.cc 
b/source/blender/blenvm/intern/bvm_api.cc
index f22dfdc..f60681d 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -1164,7 +1164,6 @@ void BVM_eval_dupli(struct BVMEvalGlobals *globals,
                        BKE_dupli_add_instance(duplicont, dupli.object, (float 
(*)[4])dupli.transform.data, dupli.index,
                                               false, dupli.hide, 
dupli.recursive);
                }
-               
-               delete duplis;
        }
+       result.clear();
 }
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h 
b/source/blender/blenvm/util/bvm_util_typedesc.h
index e02706a..4640261 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -205,7 +205,14 @@ struct node_data_ptr {
        }
        
        element_type* get() const { return m_data; }
-       void set(element_type *data) { m_data = data; }
+       void set(element_type *data)
+       {
+               if (m_data != data) {
+                       if (m_data)
+                               DestructorT::destroy(m_data);
+                       m_data = data;
+               }
+       }
        
        element_type& operator * () const { return *m_data; }
        element_type* operator -> () const { return m_data; }
@@ -222,17 +229,11 @@ struct node_data_ptr {
                assert(m_refs != 0 && *m_refs > 0);
                size_t count = --(*m_refs);
                if (count == 0) {
-                       if (m_data) {
-                               DestructorT::destroy(m_data);
-                               m_data = 0;
-                       }
-                       if (m_refs) {
-                               destroy_refs(m_refs);
-                       }
+                       clear();
                }
        }
        
-       void clear_use_count()
+       void clear()
        {
                if (m_data) {
                        DestructorT::destroy(m_data);
@@ -240,6 +241,7 @@ struct node_data_ptr {
                }
                if (m_refs) {
                        destroy_refs(m_refs);
+                       m_refs = 0;
                }
        }
        
@@ -315,6 +317,7 @@ typedef node_data_ptr<DupliList> duplis_ptr;
 inline void create_empty_mesh(mesh_ptr &p)
 {
        DerivedMesh *dm = CDDM_new(0, 0, 0, 0, 0);
+       /* prevent the DM from getting freed */
        dm->needsFree = 0;
        p.set(dm);
 }
@@ -322,9 +325,9 @@ inline void create_empty_mesh(mesh_ptr &p)
 inline void destroy_empty_mesh(mesh_ptr &p)
 {
        DerivedMesh *dm = p.get();
+       /* have to set this back so the DM actually gets freed */
        dm->needsFree = 1;
-       dm->release(dm);
-       p.set(NULL);
+       p.clear();
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to