Преглед изворни кода

Don't mix and match memory de-allocation functions (bug 537)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@36484 15284696-431f-4ddb-bdfa-cd5b030d7da7
Paul Kelly пре 16 година
родитељ
комит
c2a4cfca8d
1 измењених фајлова са 12 додато и 6 уклоњено
  1. 12 6
      lib/proj/convert.c

+ 12 - 6
lib/proj/convert.c

@@ -54,7 +54,7 @@ char *GPJ_grass_to_wkt(struct Key_Value *proj_info,
 		       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 @@ char *GPJ_grass_to_wkt(struct Key_Value *proj_info,
     else
 	OSRExportToWkt(hSRS, &wkt);
 
+    local_wkt = G_store(wkt);
+    CPLFree(wkt);
     OSRDestroySpatialReference(hSRS);
-    return wkt;
+    return local_wkt;
 }
 
 /**
@@ -317,7 +319,11 @@ int GPJ_osr_to_grass(struct Cell_head *cellhd, struct Key_Value **projinfo,
     /* -------------------------------------------------------------------- */
     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 @@ int GPJ_osr_to_grass(struct Cell_head *cellhd, struct Key_Value **projinfo,
 	G_free_key_value(temp_projinfo);
     }
 
-    free(pszProj4);		/* hopefully the same as CPLFree()! */
+    G_free(pszProj4);
 
     /* -------------------------------------------------------------------- */
     /*      Set the linear units.                                           */
@@ -789,8 +795,8 @@ static void DatumNameMassage(char **ppszDatum)
     /* -------------------------------------------------------------------- */
     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;
 	}
     }