diff options
author | Bastien Montagne <bastien@blender.org> | 2021-03-22 17:01:38 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-03-22 17:10:27 +0300 |
commit | 56dabfac5cba8d4762579120e6416230af1465d9 (patch) | |
tree | aa7e3972736af4d2cc44a552127a91d4edb7f508 /source/blender/blenkernel/intern/layer.c | |
parent | 7b7b554f9467c36e404b26cfbea6774f6d32db64 (diff) |
Fix (unreported) memleak in collection/viewlayer code.
In collection/viewlayer synchronization code, in some cases, there are
extra unused view layer collections left in old list after all needed
ones have been moved to the new list.
Found while working on T86741.
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index fbad0d920ed..2ac10586fd9 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -885,6 +885,21 @@ static void layer_collection_sync(ViewLayer *view_layer, } } + /* Free potentially remaining unused layer collections in old list. + * NOTE: While this does not happen in typical situations, some corner cases (like remapping + * several different collections to a single one) can lead to this list having extra unused + * items. */ + LISTBASE_FOREACH_MUTABLE (LayerCollection *, lc, lb_layer_collections) { + if (lc == view_layer->active_collection) { + view_layer->active_collection = NULL; + } + + /* Free recursively. */ + layer_collection_free(view_layer, lc); + BLI_freelinkN(lb_layer_collections, lc); + } + BLI_assert(BLI_listbase_is_empty(lb_layer_collections)); + /* Replace layer collection list with new one. */ *lb_layer_collections = new_lb_layer; BLI_assert(BLI_listbase_count(lb_collections) == BLI_listbase_count(lb_layer_collections)); |