[GRASS-SVN] r36484 - grass/trunk/lib/proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 25 11:22:01 EDT 2009


Author: pkelly
Date: 2009-03-25 11:22:01 -0400 (Wed, 25 Mar 2009)
New Revision: 36484

Modified:
   grass/trunk/lib/proj/convert.c
Log:
Don't mix and match memory de-allocation functions (bug 537)


Modified: grass/trunk/lib/proj/convert.c
===================================================================
--- grass/trunk/lib/proj/convert.c	2009-03-25 13:53:42 UTC (rev 36483)
+++ grass/trunk/lib/proj/convert.c	2009-03-25 15:22:01 UTC (rev 36484)
@@ -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;
 }
 
 /**
@@ -317,7 +319,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;
 
@@ -567,7 +573,7 @@
 	G_free_key_value(temp_projinfo);
     }
 
-    free(pszProj4);		/* hopefully the same as CPLFree()! */
+    G_free(pszProj4);
 
     /* -------------------------------------------------------------------- */
     /*      Set the linear units.                                           */
@@ -789,8 +795,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