[fusion-commits] Animation plugin: Changes to 'master' (a12191dbab90734ec93839fdae45b190ef232e25)

cornelius at server.beryl-project.org cornelius at server.beryl-project.org
Sun Jul 22 09:36:52 CEST 2007


New commits:
commit a12191dbab90734ec93839fdae45b190ef232e25
Author: Erkin Bahceci <erkinbah at gmail.com>
Date:   Sun Jul 22 03:36:20 2007 -0400

    Minor code reorganization.

commit 81785936221f109fd32bbec996b0f784c441e351
Author: Erkin Bahceci <erkinbah at gmail.com>
Date:   Sun Jul 22 03:26:25 2007 -0400

    Plug the memory leak.


 animation.c |   47 ++++++++++++++++++++++-------------------------
 beamup.c    |    2 +-
 burn.c      |    2 +-
 domino.c    |    2 +-
 magiclamp.c |    2 +-
 particle.c  |    2 +-
 polygon.c   |   24 +++++++++++-------------
 7 files changed, 38 insertions(+), 43 deletions(-)


Modified: fusion/plugins/animation/animation.c
===================================================================
--- fusion/plugins/animation/animation.c
+++ fusion/plugins/animation/animation.c
@@ -251,7 +251,10 @@ matchWithString(CompWindow *w, const char *matchStr)
     matchAddFromString (&match, (char *)matchStr);
     matchUpdate (d, &match);
 
-    return matchEval (&match, w);
+    Bool result = matchEval (&match, w);
+    matchFini (&match);
+
+    return result;
 }
 
 // Can be moved to the Workarounds plugin when
@@ -1078,7 +1081,7 @@ static Model *createModel(CompWindow * w,
     model->gridWidth = gridWidth;
     model->gridHeight = gridHeight;
     model->numObjects = gridWidth * gridHeight;
-    model->objects = calloc(1, sizeof(Object) * model->numObjects);
+    model->objects = calloc(model->numObjects, sizeof(Object));
     if (!model->objects)
     {
 	compLogMessage (w->screen->display, "animation", CompLogLevelError,
@@ -1110,6 +1113,20 @@ static Model *createModel(CompWindow * w,
     return model;
 }
 
+static void
+animFreeModel(AnimWindow *aw)
+{
+    if (!aw->model)
+	return;
+
+    if (aw->model->magicLampWaves)
+	free(aw->model->magicLampWaves);
+    if (aw->model->objects)
+	free(aw->model->objects);
+    free(aw->model);
+    aw->model = NULL;
+}
+
 static Bool
 animEnsureModel(CompWindow * w,
 		WindowEvent forWindowEvent, AnimEffect forAnimEffect)
@@ -1140,13 +1157,7 @@ animEnsureModel(CompWindow * w,
 	(isShadeUnshadeEvent != wasShadeUnshadeEvent) ||
 	aw->model->winWidth != WIN_W(w) || aw->model->winHeight != WIN_H(w))
     {
-	if (aw->model)
-	{
-	    if (aw->model->magicLampWaves)
-		free(aw->model->magicLampWaves);
-	    free(aw->model->objects);
-	    free(aw->model);
-	}
+	animFreeModel(aw);
 	aw->model = createModel(w,
 				forWindowEvent, forAnimEffect,
 				gridWidth, gridHeight);
@@ -3316,7 +3327,7 @@ static void animHandleEvent(CompDisplay * d, XEvent * event)
 		AnimWindow *awRestacked = GET_ANIM_WINDOW(wRestacked, as);
 		if (awRestacked->created)
 		{
-		    RestackInfo *restackInfo = calloc(sizeof(RestackInfo), 1);
+		    RestackInfo *restackInfo = calloc(1, sizeof(RestackInfo));
 		    if (restackInfo)
 		    {
 			restackInfo->wRestacked = wRestacked;
@@ -4068,21 +4079,7 @@ static void animFiniWindow(CompPlugin * p, CompWindow * w)
 
     postAnimationCleanup(w, FALSE);
 
-    if (aw->model)
-    {
-	if (aw->model->magicLampWaves)
-	    free(aw->model->magicLampWaves);
-	aw->model->magicLampWaves = 0;
-	free(aw->model->objects);
-	aw->model->objects = 0;
-	free(aw->model);
-	aw->model = 0;
-    }
-    if (aw->restackInfo)
-    {
-	free(aw->restackInfo);
-	aw->restackInfo = NULL;
-    }
+    animFreeModel(aw);
 
     while (aw->unmapCnt--)
 	unmapWindow(w);

Modified: fusion/plugins/animation/beamup.c
===================================================================
--- fusion/plugins/animation/beamup.c
+++ fusion/plugins/animation/beamup.c
@@ -48,7 +48,7 @@ void fxBeamUpInit(CompScreen * s, CompWindow * w)
     ANIM_SCREEN(s);
     if (!aw->numPs)
     {
-	aw->ps = calloc(1, 2 * sizeof(ParticleSystem));
+	aw->ps = calloc(2, sizeof(ParticleSystem));
 	if (!aw->ps)
 	{
 	    postAnimationCleanup(w, TRUE);

Modified: fusion/plugins/animation/burn.c
===================================================================
--- fusion/plugins/animation/burn.c
+++ fusion/plugins/animation/burn.c
@@ -47,7 +47,7 @@ void fxBurnInit(CompScreen * s, CompWindow * w)
     modelInitObjects(aw->model, WIN_X(w), WIN_Y(w), WIN_W(w), WIN_H(w));
     if (!aw->numPs)
     {
-	aw->ps = calloc(1, 2 * sizeof(ParticleSystem));
+	aw->ps = calloc(2, sizeof(ParticleSystem));
 	if (!aw->ps)
 	{
 	    postAnimationCleanup(w, TRUE);

Modified: fusion/plugins/animation/domino.c
===================================================================
--- fusion/plugins/animation/domino.c
+++ fusion/plugins/animation/domino.c
@@ -174,7 +174,7 @@ void fxDomino3DInit(CompScreen * s, CompWindow * w)
 	fadeDuration = 0.18;
 	riseDuration = 0.2;
     }
-    float *riseTimeRandSeed = calloc(1, nFallingColumns * sizeof(float));
+    float *riseTimeRandSeed = calloc(nFallingColumns, sizeof(float));
 
     if (!riseTimeRandSeed)
 	// TODO: log error here

Modified: fusion/plugins/animation/magiclamp.c
===================================================================
--- fusion/plugins/animation/magiclamp.c
+++ fusion/plugins/animation/magiclamp.c
@@ -97,7 +97,7 @@ void fxMagicLampInit(CompScreen * s, CompWindow * w)
 
 	if (!(model->magicLampWaves))
 	    model->magicLampWaves =
-		calloc(1, model->magicLampWaveCount * sizeof(WaveParam));
+		calloc(model->magicLampWaveCount, sizeof(WaveParam));
 
 	int ampDirection = (RAND_FLOAT() < 0.5 ? 1 : -1);
 	int i;

Modified: fusion/plugins/animation/particle.c
===================================================================
--- fusion/plugins/animation/particle.c
+++ fusion/plugins/animation/particle.c
@@ -40,7 +40,7 @@ void initParticles(int numParticles, ParticleSystem * ps)
 {
     if (ps->particles)
 	free(ps->particles);
-    ps->particles = calloc(1, sizeof(Particle) * numParticles);
+    ps->particles = calloc(numParticles, sizeof(Particle));
     ps->tex = 0;
     ps->numParticles = numParticles;
     ps->slowdown = 1;

Modified: fusion/plugins/animation/polygon.c
===================================================================
--- fusion/plugins/animation/polygon.c
+++ fusion/plugins/animation/polygon.c
@@ -218,7 +218,7 @@ tessellateIntoRectangles(CompWindow * w,
 
 	pset->nPolygons = gridSizeX * gridSizeY;
 
-	pset->polygons = calloc(1, sizeof(PolygonObject) * pset->nPolygons);
+	pset->polygons = calloc(pset->nPolygons, sizeof(PolygonObject));
 	if (!pset->polygons)
 	{
 	    compLogMessage (w->screen->display, "animation", CompLogLevelError,
@@ -266,7 +266,7 @@ tessellateIntoRectangles(CompWindow * w,
 	    // 4 front, 4 back vertices
 	    if (!p->vertices)
 	    {
-		p->vertices = calloc(1, sizeof(GLfloat) * 8 * 3);
+		p->vertices = calloc(8 * 3, sizeof(GLfloat));
 	    }
 	    //if (!p->vertexOnEdge)
 	    //  p->vertexOnEdge = calloc (1, sizeof (int) * p->nSides);
@@ -319,8 +319,7 @@ tessellateIntoRectangles(CompWindow * w,
 	    // 16 indices for 4 sides (for quad strip)
 	    if (!p->sideIndices)
 	    {
-		//p->sideIndices = calloc(1, sizeof(GLushort) * 2 * (4 + 1));
-		p->sideIndices = calloc(1, sizeof(GLushort) * 4 * 4);
+		p->sideIndices = calloc(4 * 4, sizeof(GLushort));
 	    }
 	    if (!p->sideIndices)
 	    {
@@ -370,7 +369,7 @@ tessellateIntoRectangles(CompWindow * w,
 	    // Surface normals
 	    if (!p->normals)
 	    {
-		p->normals = calloc(1, sizeof(GLfloat) * (2 + 4) * 3);
+		p->normals = calloc((2 + 4) * 3, sizeof(GLfloat));
 	    }
 	    if (!p->normals)
 	    {
@@ -491,7 +490,7 @@ tessellateIntoHexagons(CompWindow * w,
 
 	pset->nPolygons = nPolygons;
 
-	pset->polygons = calloc(1, sizeof(PolygonObject) * pset->nPolygons);
+	pset->polygons = calloc(pset->nPolygons, sizeof(PolygonObject));
 	if (!pset->polygons)
 	{
 	    compLogMessage (w->screen->display, "animation", CompLogLevelError,
@@ -575,7 +574,7 @@ tessellateIntoHexagons(CompWindow * w,
 	    // 6 front, 6 back vertices
 	    if (!p->vertices)
 	    {
-		p->vertices = calloc(1, sizeof(GLfloat) * 6 * 2 * 3);
+		p->vertices = calloc(6 * 2 * 3, sizeof(GLfloat));
 		if (!p->vertices)
 		{
 		    compLogMessage (w->screen->display, "animation", CompLogLevelError,
@@ -642,7 +641,7 @@ tessellateIntoHexagons(CompWindow * w,
 	    // 24 indices per 6 sides (for quad strip)
 	    if (!p->sideIndices)
 	    {
-		p->sideIndices = calloc(1, sizeof(GLushort) * 4*6);
+		p->sideIndices = calloc(4 * 6, sizeof(GLushort));
 	    }
 	    if (!p->sideIndices)
 	    {
@@ -690,7 +689,7 @@ tessellateIntoHexagons(CompWindow * w,
 	    // Surface normals
 	    if (!p->normals)
 	    {
-		p->normals = calloc(1, sizeof(GLfloat) * (2 + 6) * 3);
+		p->normals = calloc((2 + 6) * 3, sizeof(GLfloat));
 	    }
 	    if (!p->normals)
 	    {
@@ -977,16 +976,15 @@ static Bool processIntersectingPolygons(CompScreen * s, PolygonSet * pset)
 
 	    if (!c->intersectingPolygons)
 	    {
-		c->intersectingPolygons = calloc(1, sizeof(int) *
-						 pset->nPolygons);
+		c->intersectingPolygons =
+		    calloc(pset->nPolygons, sizeof(int));
 	    }
 	    // allocate tex coords
 	    // 2 {x, y} * 2 {front, back} * <total # of polygon front vertices>
 	    if (!c->polygonVertexTexCoords)
 	    {
 		c->polygonVertexTexCoords =
-		    calloc(1, sizeof(GLfloat) * 2 * 2 *
-			   pset->nTotalFrontVertices);
+		    calloc(2 * 2 * pset->nTotalFrontVertices, sizeof(GLfloat));
 	    }
 	    if (!c->intersectingPolygons || !c->polygonVertexTexCoords)
 	    {


More information about the commits mailing list