diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-10-13 12:59:56 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-10-13 12:59:56 +0300 |
commit | 0558907ae674ebe81dc8910a6615fc32ce675d70 (patch) | |
tree | 76408325233c21cb63573c41ce099878b8d25083 /source/blender/depsgraph/intern/eval | |
parent | 86536e785902c35a197bfef099693c00e8fc1bee (diff) |
Fix T92136: Leak accessing evaluated depsgraph data from Python
Diffstat (limited to 'source/blender/depsgraph/intern/eval')
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc | 11 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc index a844d23b558..610e4860108 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc @@ -853,6 +853,10 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph, if (!deg_copy_on_write_is_needed(id_orig)) { return id_cow; } + /* Avoid removing & re-creating the reference if it exists. */ + void *py_instance = id_cow->py_instance; + id_cow->py_instance = nullptr; + DEG_COW_PRINT( "Expanding datablock for %s: id_orig=%p id_cow=%p\n", id_orig->name, id_orig, id_cow); /* Sanity checks. */ @@ -925,6 +929,7 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph, * from above. */ update_id_after_copy(depsgraph, id_node, id_orig, id_cow); id_cow->recalc = id_cow_recalc; + id_cow->py_instance = py_instance; return id_cow; } @@ -1042,6 +1047,11 @@ void discard_edit_mode_pointers(ID *id_cow) * - Does not free data-block itself. */ void deg_free_copy_on_write_datablock(ID *id_cow) { + /* There may be Python references to to shallow copies, see: T92136. */ + if (id_cow->py_instance) { + BKE_libblock_free_data_py(id_cow); + } + if (!check_datablock_expanded(id_cow)) { /* Actual content was never copied on top of CoW block, we have * nothing to free. */ @@ -1103,6 +1113,7 @@ void deg_tag_copy_on_write_id(ID *id_cow, const ID *id_orig) /* This ID is no longer localized, is a self-sustaining copy now. */ id_cow->tag &= ~LIB_TAG_LOCALIZED; id_cow->orig_id = (ID *)id_orig; + BLI_assert(id_cow->py_instance == nullptr); } bool deg_copy_on_write_is_expanded(const ID *id_cow) 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 7893e8c64c1..c6e3532aca9 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup.cc @@ -52,7 +52,9 @@ void RuntimeBackup::init_from_id(ID *id) } have_backup = true; + /* Clear, so freeing the expanded data doesn't remove this Python reference. */ id_data.py_instance = id->py_instance; + id->py_instance = nullptr; animation_backup.init_from_id(id); |