Fix #144483: Use-after-free when splitting View3D opened Asset Shelf
`asset_shelf::regiondata_duplicate()` first creates a shallow copy of the `AssetShelf`, including its `AssetShelfSettings` member. So the contained pointer point to the same memory. While this is a rather unusual case for a copy assignment operator to consider, I think this is fine since the API allows these shadow copies. This is a bit of a consequence of mixing C and C++ style memory management. Pull Request: https://projects.blender.org/blender/blender/pulls/144613
This commit is contained in:
committed by
Julian Eisel
parent
a3c4b0b07a
commit
075c2eca06
@@ -395,6 +395,10 @@ BLI_INLINE bool operator==(const ListBase &a, const ListBase &b)
|
||||
{
|
||||
return BLI_listbase_equal(&a, &b);
|
||||
}
|
||||
BLI_INLINE bool operator!=(const ListBase &a, const ListBase &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
template<typename T, typename Fn> T *BLI_listbase_find(const ListBase &listbase, Fn &&predicate)
|
||||
{
|
||||
|
||||
@@ -41,9 +41,14 @@ AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &othe
|
||||
return *this; /* Handle self-assignment safely. */
|
||||
}
|
||||
|
||||
/* Free existing properties. */
|
||||
BKE_asset_catalog_path_list_free(this->enabled_catalog_paths);
|
||||
MEM_SAFE_FREE(this->active_catalog_path);
|
||||
/* Free existing properties. Check if they point to the same memory first, #AssetShelfSettings
|
||||
* might have been shallow copied before. */
|
||||
if (this->enabled_catalog_paths != other.enabled_catalog_paths) {
|
||||
BKE_asset_catalog_path_list_free(this->enabled_catalog_paths);
|
||||
}
|
||||
if (this->active_catalog_path != other.active_catalog_path) {
|
||||
MEM_SAFE_FREE(this->active_catalog_path);
|
||||
}
|
||||
|
||||
/* Copy from 'other'. */
|
||||
this->asset_library_reference = other.asset_library_reference;
|
||||
|
||||
Reference in New Issue
Block a user