[Bf-blender-cvs] [47cc05471d1] blender-v2.83-release: Fix T86170: Memory leak clearing the Python instance for COW id data

Campbell Barton noreply at git.blender.org
Fri May 7 07:57:43 CEST 2021


Commit: 47cc05471d1c046ad89b7e60f52157ca7dcda075
Author: Campbell Barton
Date:   Fri Apr 23 09:02:49 2021 +1000
Branches: blender-v2.83-release
https://developer.blender.org/rB47cc05471d1c046ad89b7e60f52157ca7dcda075

Fix T86170: Memory leak clearing the Python instance for COW id data

As Python can access COW ID's, ensure it's instance is kept on update.

This could happen when the "Use Self" argument was enabled for a driver.

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

M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.h

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

diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc
index c3733cb235c..12b841b4a1a 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc
@@ -33,6 +33,7 @@ namespace DEG {
 
 RuntimeBackup::RuntimeBackup(const Depsgraph *depsgraph)
     : have_backup(false),
+      id_data({.py_instance = nullptr}),
       animation_backup(depsgraph),
       scene_backup(depsgraph),
       sound_backup(depsgraph),
@@ -51,6 +52,8 @@ void RuntimeBackup::init_from_id(ID *id)
   }
   have_backup = true;
 
+  id_data.py_instance = id->py_instance;
+
   animation_backup.init_from_id(id);
 
   const ID_Type id_type = GS(id->name);
@@ -89,6 +92,8 @@ void RuntimeBackup::restore_to_id(ID *id)
     return;
   }
 
+  id->py_instance = id_data.py_instance;
+
   animation_backup.restore_to_id(id);
 
   const ID_Type id_type = GS(id->name);
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.h b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.h
index dde7d0b2782..ab992e58490 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.h
+++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.h
@@ -57,6 +57,11 @@ class RuntimeBackup {
    * copy-on-write mechanism. */
   bool have_backup;
 
+  /* Struct members of the ID pointer. */
+  struct {
+    void *py_instance;
+  } id_data;
+
   AnimationBackup animation_backup;
   SceneBackup scene_backup;
   SoundBackup sound_backup;



More information about the Bf-blender-cvs mailing list