diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-08-29 15:49:54 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-08-29 15:49:54 +0300 |
commit | 7f23c914781268977b464a3c0dcba2f89e01dc36 (patch) | |
tree | 75a7e1c73db0b15e7e4310233a57c72695cdcdcc /source/blender/blenkernel/intern/library_override.c | |
parent | 6b33bd1067dc34711e0e076070cfaeaf0e3259a5 (diff) |
LibOverride: Fix use-after-free error when freeing whole Main DB.
We do not want to touch to other ID pointers in that case, those might
have already been freed...
Diffstat (limited to 'source/blender/blenkernel/intern/library_override.c')
-rw-r--r-- | source/blender/blenkernel/intern/library_override.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c index ce368575492..ba482359607 100644 --- a/source/blender/blenkernel/intern/library_override.c +++ b/source/blender/blenkernel/intern/library_override.c @@ -111,11 +111,11 @@ void BKE_override_library_copy(ID *dst_id, const ID *src_id) if (dst_id->override_library != NULL) { if (src_id->override_library == NULL) { - BKE_override_library_free(&dst_id->override_library); + BKE_override_library_free(&dst_id->override_library, true); return; } else { - BKE_override_library_clear(dst_id->override_library); + BKE_override_library_clear(dst_id->override_library, true); } } else if (src_id->override_library == NULL) { @@ -144,7 +144,7 @@ void BKE_override_library_copy(ID *dst_id, const ID *src_id) } /** Clear any overriding data from given \a override. */ -void BKE_override_library_clear(IDOverrideLibrary *override) +void BKE_override_library_clear(IDOverrideLibrary *override, const bool do_id_user) { BLI_assert(override != NULL); @@ -153,16 +153,18 @@ void BKE_override_library_clear(IDOverrideLibrary *override) } BLI_freelistN(&override->properties); - id_us_min(override->reference); - /* override->storage should never be refcounted... */ + if (do_id_user) { + id_us_min(override->reference); + /* override->storage should never be refcounted... */ + } } /** Free given \a override. */ -void BKE_override_library_free(struct IDOverrideLibrary **override) +void BKE_override_library_free(struct IDOverrideLibrary **override, const bool do_id_user) { BLI_assert(*override != NULL); - BKE_override_library_clear(*override); + BKE_override_library_clear(*override, do_id_user); MEM_freeN(*override); *override = NULL; } |