[GRASS-SVN] r48371 -
grass/branches/releasebranch_6_4/raster/r.texture
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 19 15:45:55 EDT 2011
Author: neteler
Date: 2011-09-19 12:45:55 -0700 (Mon, 19 Sep 2011)
New Revision: 48371
Modified:
grass/branches/releasebranch_6_4/raster/r.texture/h_measure.c
Log:
mmetz: fix memory leaks (backport of trunk r47112)
Modified: grass/branches/releasebranch_6_4/raster/r.texture/h_measure.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.texture/h_measure.c 2011-09-19 19:39:30 UTC (rev 48370)
+++ grass/branches/releasebranch_6_4/raster/r.texture/h_measure.c 2011-09-19 19:45:55 UTC (rev 48371)
@@ -58,10 +58,10 @@
**matrix();
-float **P_matrix0;
-float **P_matrix45;
-float **P_matrix90;
-float **P_matrix135;
+static float **P_matrix0 = NULL;
+static float **P_matrix45 = NULL;
+static float **P_matrix90 = NULL;
+static float **P_matrix135 = NULL;
int tone[PGM_MAXMAXVAL + 1];
@@ -454,6 +454,8 @@
for (j = 0; j < Ng; ++j)
tmp += i * j * P[i][j];
+ G_free(px);
+
return (tmp - meanx * meany) / (stddevx * stddevy);
/*
* This correlation feature is a measure of gray-tone linear-dependencies
@@ -660,6 +662,8 @@
hx -= px[i] * log10(px[i] + EPSILON);
hy -= py[i] * log10(py[i] + EPSILON);
}
+ G_free(px);
+ G_free(py);
/* fprintf(stderr,"hxy1=%f\thxy=%f\thx=%f\thy=%f\n",hxy1,hxy,hx,hy); */
return ((hxy - hxy1) / (hx > hy ? hx : hy));
}
@@ -698,6 +702,8 @@
hx -= px[i] * log10(px[i] + EPSILON);
hy -= py[i] * log10(py[i] + EPSILON);
}
+ G_free(px);
+ G_free(py);
/* fprintf(stderr,"hx=%f\thxy2=%f\n",hx,hxy2); */
return (sqrt(abs(1 - exp(-2.0 * (hxy2 - hxy)))));
}
@@ -746,6 +752,12 @@
/* Returns the sqrt of the second largest eigenvalue of Q */
for (i = 2, tmp = x[1]; i <= Ng; ++i)
tmp = (tmp > x[i]) ? tmp : x[i];
+
+ MatrixDealloc(Q, Ng);
+ G_free(px);
+ G_free(py);
+ G_free(x);
+ G_free(iy);
return sqrt(x[Ng - 1]);
}
@@ -756,7 +768,7 @@
v = (float *)G_malloc((unsigned)(nh - nl + 1) * sizeof(float));
if (!v)
G_fatal_error(_("Unable to allocate memory")), exit(EXIT_FAILURE);
- return v - nl;
+ return v;
}
@@ -769,12 +781,10 @@
/* allocate pointers to rows */
m = (float **)G_malloc((unsigned)(nrh - nrl + 1) * sizeof(float *));
- m -= ncl;
- /* allocate rows and set pointers to them */
- for (i = nrl; i <= nrh; i++) {
+ /* allocate rows */
+ for (i = 0; i < (nrh - nrl + 1); i++) {
m[i] = (float *)G_malloc((unsigned)(nch - ncl + 1) * sizeof(float));
- m[i] -= ncl;
}
/* return pointer to array of pointers to rows */
return m;
More information about the grass-commit
mailing list