<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>> Hi,</p>
<p>></p>
<p>> I have a serious crash in one of my Matlab MEXs caused by a call to</p>
<p>> OGRFree() with an argument of size one (possibly the null terminator).</p>
<p>> This happens on OSX SL (64 bits) but not on Windows (where I still</p>
<p>> build at 32 bits)</p>
<p>></p>
<p>> Here is, as far as I could trace it, what is happening (SVN version of</p>
<p>> the same age as GDAL1.7RC1)</p>
<p>></p>
<p>> mexPrintf("---- %s\n%s\n", pszSrcWKT,pszDstWKT);</p>
<p>></p>
<p>> That prints</p>
<p>></p>
<p>> ---- GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS</p>
<p>> 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>>AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNI</p>
<p>>T["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","43</p>
<p>>26"]] PROJCS["UTM Zone 29, Northern Hemisphere",GEOGCS["WGS</p>
<p>> 84",DATUM["WGS_1984",SPHEROID["WGS</p>
<p>> 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>>AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNI</p>
<p>>T["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","43</p>
<p>>26"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PA</p>
<p>>RAMETER["central_meridian",-9],PARAMETER["scale_factor",0.9996],PARAMETER["f</p>
<p>>alse_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]</p>
<p>></p>
<p>></p>
<p>> Next the code does:</p>
<p>></p>
<p>>         GDALClose( hSrcDS );</p>
<p>> mexPrintf("---- %s\n%s\n", pszSrcWKT,pszDstWKT);</p>
<p>></p>
<p>> and now pszSrcWKT is empty. See</p>
<p>></p>
<p>> ---- </p>
<p>> PROJCS["UTM Zone 29, Northern Hemisphere",GEOGCS["WGS</p>
<p>> 84",DATUM["WGS_1984",SPHEROID["WGS</p>
<p>> 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],</p>
<p>>AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNI</p>
<p>>T["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","43</p>
<p>>26"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PA</p>
<p>>RAMETER["central_meridian",-9],PARAMETER["scale_factor",0.9996],PARAMETER["f</p>
<p>>alse_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]</p>
<p>></p>
<p>> If I make it print the size of pszSrcWKT with strlen(pszSrcWKT) the</p>
<p>> answer is 1 and finally the MEX (and the entire MATLAB) crash on the</p>
<p>> call</p>
<p>></p>
<p>> OGRFree(pszSrcWKT);</p>
<p>></p>
<p>></p>
<p>> Joaquim Luis</p>
<p>></p>
<p>> ----------------------------------------------------------------</p>
<p>> This message was sent using IMP, the Internet Messaging Program.</p>
<p>></p>
<p>> _______________________________________________</p>
<p>> gdal-dev mailing list</p>
<p>> gdal-dev@lists.osgeo.org</p>
<p>> http://lists.osgeo.org/mailman/listinfo/gdal-dev</p>
<p></p>
<p></p>
<p></p>
</body></html>