[Vegan-commits] r1317 - pkg/gravy/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 24 14:18:17 CEST 2010


Author: jarioksa
Date: 2010-09-24 14:18:17 +0200 (Fri, 24 Sep 2010)
New Revision: 1317

Modified:
   pkg/gravy/src/hill.c
Log:
memory leak fix 2: use R_alloc

Modified: pkg/gravy/src/hill.c
===================================================================
--- pkg/gravy/src/hill.c	2010-09-24 10:23:08 UTC (rev 1316)
+++ pkg/gravy/src/hill.c	2010-09-24 12:18:17 UTC (rev 1317)
@@ -227,9 +227,9 @@
 
 
 #include <stdio.h> /* Debug */
-#include <assert.h> /* assert malloc */ 
-#include <stdlib.h> /* malloc */
 
+#include <R.h> /* R_alloc */
+
 /* Arbitrary constants, as used in DECORANA/ CANOCO */
 
 #define SEGMIN 10
@@ -252,10 +252,10 @@
      nst = *nnst;
      resc = *nresc;
 
-     assert(spWA =  (double *) malloc(nsp*sizeof(double)));
-     assert(spTol = (double *) malloc(nsp*sizeof(double)));
-     assert(fidot = (double *) malloc(nst*sizeof(double)));
-     assert(fdotj = (double *) malloc(nsp*sizeof(double)));
+     spWA =  (double *) R_alloc(nsp, sizeof(double));
+     spTol = (double *) R_alloc(nsp, sizeof(double));
+     fidot = (double *) R_alloc(nst, sizeof(double));
+     fdotj = (double *) R_alloc(nsp, sizeof(double));
 
      /* Make the axis start from zero, like it would start in DECORANA. */
  
@@ -404,11 +404,6 @@
 
 	  } /* End the pass (cycle) 200 */
      } /* End the all resc rescaling cycles */
-     /* free what you allocated */
-     free(spWA);
-     free(spTol);
-     free(fidot);
-     free(fdotj);
 }
 
 /* Get the Hill indices of beta diversity with a segmented smooth without rescaling */
@@ -420,10 +415,10 @@
      double zn[SEGODD];
      int i;
 
-     assert(spWA =  (double *) malloc(*nnsp*sizeof(double)));
-     assert(spTol = (double *) malloc(*nnsp*sizeof(double)));
-     assert(fidot = (double *) malloc(*nnst*sizeof(double)));
-     assert(fdotj = (double *) malloc(*nnsp*sizeof(double)));
+     spWA =  (double *) R_alloc(*nnsp, sizeof(double));
+     spTol = (double *) R_alloc(*nnsp, sizeof(double));
+     fidot = (double *) R_alloc(*nnst, sizeof(double));
+     fdotj = (double *) R_alloc(*nnsp, sizeof(double));
 
      GetWA (f,x, nnsp, nnst, spWA, spTol);
      Marginals(f, nnsp, nnst, fidot, fdotj, &fdotdot);
@@ -437,9 +432,4 @@
 	  zv1[i] = zv1[i]/zn[i];
 	  zv2[i] = zv2[i]/zn[i];
      }
-     /* free */
-     free(spWA);
-     free(spTol);
-     free(fidot);
-     free(fdotj);
 }



More information about the Vegan-commits mailing list