<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p>Joaquim,</p>
<p></p>
<p>you don't provide enough code to really see what's wrong, but my guess is that you misuse GDAL API.</p>
<p></p>
<p>If you get pszSrcWKT, with</p>
<p></p>
<p>pszSrcWKT = GDALGetProjectionRef(hDS);</p>
<p></p>
<p>The pszSrcWKT string is owned by the hDS object, so as soon as you destroy the hDS object with GDALClose(), the pointer becomes invalid and points to arbitrary data.</p>
<p></p>
<p>For the same reason, you should never free the string returned by GDALGetProjectionRef() with OGRFree() or any other free() call.</p>
<p></p>
<p>See http://gdal.org/classGDALDataset.html :</p>
<p></p>
<p>GDALDataset::GetProjectionRef() :</p>
<p></p>
<p>returns:</p>
<p>a pointer to an internal reference string. It should not be altered, freed or expected to last for long.</p>
<p></p>
<p>Best regards,</p>
<p></p>
<p>Even</p>
<p></p>
<p>Le Saturday 23 January 2010 16:04:58 jluis@ualg.pt, vous avez écrit :</p>
<p>&gt; Hi,</p>
<p>&gt;</p>
<p>&gt; I have a serious crash in one of my Matlab MEXs caused by a call to</p>
<p>&gt; OGRFree() with an argument of size one (possibly the  null terminator).</p>
<p>&gt; This happens on OSX SL (64 bits) but not on Windows (where I still</p>
<p>&gt; build at 32 bits)</p>
<p>&gt;</p>
<p>&gt; Here is, as far as I could trace it, what is happening (SVN version of</p>
<p>&gt; the same age as GDAL1.7RC1)</p>
<p>&gt;</p>
<p>&gt; mexPrintf(&quot;---- %s\n%s\n&quot;, pszSrcWKT,pszDstWKT);</p>
<p>&gt;</p>
<p>&gt; That prints</p>
<p>&gt;</p>
<p>&gt; ---- GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS</p>
<p>&gt; 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>&gt;AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNI</p>
<p>&gt;T[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9108&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;43</p>
<p>&gt;26&quot;]] PROJCS[&quot;UTM Zone 29, Northern Hemisphere&quot;,GEOGCS[&quot;WGS</p>
<p>&gt; 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS</p>
<p>&gt; 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>&gt;AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNI</p>
<p>&gt;T[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9108&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;43</p>
<p>&gt;26&quot;]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;latitude_of_origin&quot;,0],PA</p>
<p>&gt;RAMETER[&quot;central_meridian&quot;,-9],PARAMETER[&quot;scale_factor&quot;,0.9996],PARAMETER[&quot;f</p>
<p>&gt;alse_easting&quot;,500000],PARAMETER[&quot;false_northing&quot;,0],UNIT[&quot;Meter&quot;,1]]</p>
<p>&gt;</p>
<p>&gt;</p>
<p>&gt; Next the code does:</p>
<p>&gt;</p>
<p>&gt;         GDALClose( hSrcDS );</p>
<p>&gt; mexPrintf(&quot;---- %s\n%s\n&quot;, pszSrcWKT,pszDstWKT);</p>
<p>&gt;</p>
<p>&gt; and now pszSrcWKT is empty. See</p>
<p>&gt;</p>
<p>&gt; ---- </p>
<p>&gt; PROJCS[&quot;UTM Zone 29, Northern Hemisphere&quot;,GEOGCS[&quot;WGS</p>
<p>&gt; 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS</p>
<p>&gt; 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>&gt;AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNI</p>
<p>&gt;T[&quot;degree&quot;,0.0174532925199433,AUTHORITY[&quot;EPSG&quot;,&quot;9108&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;43</p>
<p>&gt;26&quot;]],PROJECTION[&quot;Transverse_Mercator&quot;],PARAMETER[&quot;latitude_of_origin&quot;,0],PA</p>
<p>&gt;RAMETER[&quot;central_meridian&quot;,-9],PARAMETER[&quot;scale_factor&quot;,0.9996],PARAMETER[&quot;f</p>
<p>&gt;alse_easting&quot;,500000],PARAMETER[&quot;false_northing&quot;,0],UNIT[&quot;Meter&quot;,1]]</p>
<p>&gt;</p>
<p>&gt; If I make it print the size of pszSrcWKT  with strlen(pszSrcWKT) the</p>
<p>&gt; answer is 1 and finally the MEX (and the entire MATLAB) crash on the</p>
<p>&gt; call</p>
<p>&gt;</p>
<p>&gt; OGRFree(pszSrcWKT);</p>
<p>&gt;</p>
<p>&gt;</p>
<p>&gt; Joaquim Luis</p>
<p>&gt;</p>
<p>&gt; ----------------------------------------------------------------</p>
<p>&gt; This message was sent using IMP, the Internet Messaging Program.</p>
<p>&gt;</p>
<p>&gt; _______________________________________________</p>
<p>&gt; gdal-dev mailing list</p>
<p>&gt; gdal-dev@lists.osgeo.org</p>
<p>&gt; http://lists.osgeo.org/mailman/listinfo/gdal-dev</p>
<p></p>
<p></p>
<p></p>
</body></html>