Fix T92153: use-after-free with anonymous attributes

Differential Revision: https://developer.blender.org/D12851
This commit is contained in:
Jacques Lucke 2021-10-13 15:36:52 +02:00
parent 5183653951
commit d4e8390e95
Notes: blender-bot 2023-02-13 17:26:33 +01:00
Referenced by issue #92153, Geometry Nodes: crash with the capture Attribute node
2 changed files with 6 additions and 0 deletions

View File

@ -97,6 +97,7 @@ void BKE_anonymous_attribute_id_decrement_weak(const AnonymousAttributeID *anony
{
const int new_refcount = anonymous_id->refcount_tot.fetch_sub(1) - 1;
if (new_refcount == 0) {
BLI_assert(anonymous_id->refcount_strong == 0);
delete anonymous_id;
}
}

View File

@ -2595,6 +2595,11 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
data->layers[index] = data->layers[index - 1];
}
/* Clear remaining data on the layer. The original data on the layer has been moved to another
* index. Without this, it can happen that information from the previous layer at that index
* leaks into the new layer. */
memset(data->layers + index, 0, sizeof(CustomDataLayer));
data->layers[index].type = type;
data->layers[index].flag = flag;
data->layers[index].data = newlayerdata;