diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 5f97a5ae3dc..6625a76a2a3 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2333,7 +2333,13 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData void CustomData_bmesh_init_pool(CustomData *data, int allocsize){ - if(data->totlayer)data->pool = BLI_mempool_create(data->totsize, allocsize, allocsize, 1, 0); + /* Dispose old pools before calling here to avoid leaks */ + BLI_assert(data->pool == NULL); + + /* If there are no layers, no pool is needed just yet */ + if (data->totlayer) { + data->pool = BLI_mempool_create(data->totsize, allocsize, allocsize, 1, 0); + } } void CustomData_bmesh_merge(CustomData *source, CustomData *dest, diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index dbef8aec5c9..88780425485 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -880,13 +880,16 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data) } } - void BM_add_data_layer(BMesh *bm, CustomData *data, int type) { CustomData olddata; olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; + + /* the pool is now owned by olddata and must not be shared */ + data->pool = NULL; + CustomData_add_layer(data, type, CD_DEFAULT, NULL, 0); update_data_blocks(bm, &olddata, data); @@ -899,6 +902,10 @@ void BM_add_data_layer_named(BMesh *bm, CustomData *data, int type, const char * olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; + + /* the pool is now owned by olddata and must not be shared */ + data->pool = NULL; + CustomData_add_layer_named(data, type, CD_DEFAULT, NULL, 0, name); update_data_blocks(bm, &olddata, data); @@ -911,6 +918,10 @@ void BM_free_data_layer(BMesh *bm, CustomData *data, int type) olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; + + /* the pool is now owned by olddata and must not be shared */ + data->pool = NULL; + CustomData_free_layer_active(data, type, 0); update_data_blocks(bm, &olddata, data); @@ -923,6 +934,10 @@ void BM_free_data_layer_n(BMesh *bm, CustomData *data, int type, int n) olddata= *data; olddata.layers= (olddata.layers)? MEM_dupallocN(olddata.layers): NULL; + + /* the pool is now owned by olddata and must not be shared */ + data->pool = NULL; + CustomData_free_layer(data, type, 0, CustomData_get_layer_index_n(data, type, n)); update_data_blocks(bm, &olddata, data);