Changeset 11531

Show
Ignore:
Timestamp:
05/15/07 22:37:55 (1 year ago)
Author:
warmerdam
Message:

clean up dataset/datasources that will be lost after exception (#1635)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/gdal/swig/include/gdal.i

    r10383 r11531  
    579579%inline %{ 
    580580GDALDatasetShadow* Open( char const* name, GDALAccess eAccess = GA_ReadOnly ) { 
     581  CPLErrorReset(); 
    581582  GDALDatasetShadow *ds = GDALOpen( name, eAccess ); 
     583  if( ds != NULL && CPLGetLastErrorType() == CE_Failure ) 
     584  { 
     585      if ( GDALDereferenceDataset( ds ) <= 0 ) 
     586          GDALClose(ds); 
     587      ds = NULL; 
     588  } 
    582589  return (GDALDatasetShadow*) ds; 
    583590} 
     
    587594%inline %{ 
    588595GDALDatasetShadow* OpenShared( char const* name, GDALAccess eAccess = GA_ReadOnly ) { 
     596  CPLErrorReset(); 
    589597  GDALDatasetShadow *ds = GDALOpenShared( name, eAccess ); 
     598  if( ds != NULL && CPLGetLastErrorType() == CE_Failure ) 
     599  { 
     600      if ( GDALDereferenceDataset( ds ) <= 0 ) 
     601          GDALClose(ds); 
     602      ds = NULL; 
     603  } 
    590604  return (GDALDatasetShadow*) ds; 
    591605} 
  • branches/1.4/gdal/swig/include/ogr.i

    r10412 r11531  
    14481448%inline %{ 
    14491449  OGRDataSourceShadow* Open( const char *filename, int update =0 ) { 
     1450    CPLErrorReset(); 
    14501451    OGRDataSourceShadow* ds = (OGRDataSourceShadow*)OGROpen(filename,update,NULL); 
     1452    if( CPLGetLastErrorType() == CE_Failure && ds != NULL ) 
     1453    { 
     1454        OGRReleaseDataSource(ds); 
     1455        ds = NULL; 
     1456    } 
     1457         
    14511458    return ds; 
    14521459  } 
     
    14571464%inline %{ 
    14581465  OGRDataSourceShadow* OpenShared( const char *filename, int update =0 ) { 
     1466    CPLErrorReset(); 
    14591467    OGRDataSourceShadow* ds = (OGRDataSourceShadow*)OGROpenShared(filename,update,NULL); 
     1468    if( CPLGetLastErrorType() == CE_Failure && ds != NULL ) 
     1469    { 
     1470        OGRReleaseDataSource(ds); 
     1471        ds = NULL; 
     1472    } 
     1473         
    14601474    return ds; 
    14611475  }