[GRASS-SVN] r36483 - grass/branches/develbranch_6/lib/proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 25 09:53:42 EDT 2009


Author: pkelly
Date: 2009-03-25 09:53:42 -0400 (Wed, 25 Mar 2009)
New Revision: 36483

Modified:
   grass/branches/develbranch_6/lib/proj/convert.c
Log:
Tidy up memory de-allocation for strings. Bug 537.


Modified: grass/branches/develbranch_6/lib/proj/convert.c
===================================================================
--- grass/branches/develbranch_6/lib/proj/convert.c	2009-03-25 12:20:12 UTC (rev 36482)
+++ grass/branches/develbranch_6/lib/proj/convert.c	2009-03-25 13:53:42 UTC (rev 36483)
@@ -54,7 +54,7 @@
 		       int esri_style, int prettify)
 {
     OGRSpatialReferenceH hSRS;
-    char *wkt;
+    char *wkt, *local_wkt;
 
     hSRS = GPJ_grass_to_osr(proj_info, proj_units);
 
@@ -69,8 +69,10 @@
     else
 	OSRExportToWkt(hSRS, &wkt);
 
+    local_wkt = G_store(wkt);
+    CPLFree(wkt);
     OSRDestroySpatialReference(hSRS);
-    return wkt;
+    return local_wkt;
 }
 
 /**
@@ -220,9 +222,9 @@
     OSRDestroySpatialReference(hSRS);
     G_free(modwkt);
     CPLFree(wkt);
+    pj_dalloc(proj4);
     if (proj4 != proj4mod)
-	pj_dalloc(proj4);
-    G_free(proj4mod);
+        G_free(proj4mod);
     G_free(datum);
     G_free(params);
     G_free(datumlongname);
@@ -310,7 +312,11 @@
     /* -------------------------------------------------------------------- */
     temp_projinfo = G_create_key_value();
 
-    pszRemaining = pszProj4;
+    /* Create "local" copy of proj4 string so we can modify and free it
+     * using GRASS functions */
+    pszRemaining = G_store(pszProj4);
+    CPLFree(pszProj4);
+    pszProj4 = pszRemaining;
     while ((pszRemaining = strstr(pszRemaining, "+")) != NULL) {
 	char *pszToken, *pszValue;
 
@@ -561,7 +567,7 @@
 	G_free_key_value(temp_projinfo);
     }
 
-    free(pszProj4);		/* hopefully the same as CPLFree()! */
+    G_free(pszProj4);
 
     /* -------------------------------------------------------------------- */
     /*      Set the linear units.                                           */
@@ -783,8 +789,8 @@
     /* -------------------------------------------------------------------- */
     for (i = 0; papszDatumEquiv[i] != NULL; i += 2) {
 	if (EQUAL(*ppszDatum, papszDatumEquiv[i])) {
-	    CPLFree(*ppszDatum);
-	    *ppszDatum = CPLStrdup(papszDatumEquiv[i + 1]);
+	    G_free(*ppszDatum);
+	    *ppszDatum = G_store(papszDatumEquiv[i + 1]);
 	    break;
 	}
     }



More information about the grass-commit mailing list