[Bf-blender-cvs] [9091342] alembic: Fix for memory leak when reading cached strands data with UV or vertex color layers.

Lukas Tönne noreply at git.blender.org
Fri May 1 16:10:49 CEST 2015


Commit: 909134270ad20f84dc12f539ca6dd45f06fb1306
Author: Lukas Tönne
Date:   Fri May 1 16:09:32 2015 +0200
Branches: alembic
https://developer.blender.org/rB909134270ad20f84dc12f539ca6dd45f06fb1306

Fix for memory leak when reading cached strands data with UV or vertex
color layers.

The layer data is added to the strands after creation, but can be
existing already. It should only be reallocated when the number of
layers changes, and must be freed cleanly in that case.

===================================================================

M	source/blender/blenkernel/intern/strands.c

===================================================================

diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 0c8a254..d0cf3d3 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -216,14 +216,30 @@ void BKE_strands_children_free(StrandsChildren *strands)
 
 void BKE_strands_children_add_uvs(StrandsChildren *strands, int num_layers)
 {
-	strands->curve_uvs = MEM_callocN(sizeof(StrandsChildCurveUV) * strands->totcurves * num_layers, "strands children uv layers");
-	strands->numuv = num_layers;
+	if (strands->curve_uvs && strands->numuv != num_layers) {
+		MEM_freeN(strands->curve_uvs);
+		strands->curve_uvs = NULL;
+		strands->numuv = 0;
+	}
+	
+	if (!strands->curve_uvs) {
+		strands->curve_uvs = MEM_callocN(sizeof(StrandsChildCurveUV) * strands->totcurves * num_layers, "strands children uv layers");
+		strands->numuv = num_layers;
+	}
 }
 
 void BKE_strands_children_add_vcols(StrandsChildren *strands, int num_layers)
 {
-	strands->curve_vcols = MEM_callocN(sizeof(StrandsChildCurveVCol) * strands->totcurves * num_layers, "strands children vcol layers");
-	strands->numvcol = num_layers;
+	if (strands->curve_vcols && strands->numvcol != num_layers) {
+		MEM_freeN(strands->curve_vcols);
+		strands->curve_vcols = NULL;
+		strands->numvcol = 0;
+	}
+	
+	if (!strands->curve_vcols) {
+		strands->curve_vcols = MEM_callocN(sizeof(StrandsChildCurveVCol) * strands->totcurves * num_layers, "strands children vcol layers");
+		strands->numvcol = num_layers;
+	}
 }
 
 static int *strands_calc_vertex_start(Strands *strands)




More information about the Bf-blender-cvs mailing list