[gdal-dev] Locked files under Windows

Even Rouault even.rouault at mines-paris.org
Tue Nov 5 10:59:54 PST 2013


> Even,
> 
> Thanks as always for getting back quickly! Yes, the relevant code is (line
> 475 in rgdal/src/gdal-bindings.cpp):
> 
>    GDALDataset *pDataset =
>      (GDALDataset *) R_ExternalPtrAddr(sxpHandle);
> 
>    if (pDataset == NULL) return(R_NilValue);
> 
>    installErrorHandler();
> 
>    GDALDriver *pDriver = pDataset->GetDriver();
> 
>    const char *filename = pDataset->GetDescription();
> 
>    GDALDeleteDataset((GDALDriverH) pDriver, filename);
> 
>    R_ClearExternalPtr(sxpHandle);
> 
>    uninstallErrorHandlerAndTriggerError();
> 
> but after this is run, the file remains open. Is GDALDeleteDataset()
> inappropriate? Should we say GDALClose((GDALDatasetH)pDataset); first; you
> suggested this instead of pDataset->~GDALDataset(); last year? The file
> pointers are inside the Dataset objects, so obviously they should be
> closed. We have tried putting things in various orders, without success so
> far, I'm afraid.

GDALDeleteDataset() doesn't take the dataset object as a parameter, so it will 
not delete it for you (in the C++ sense of delete... The naming of functions 
is a bit confusing admitedly)

Yes, you need to call GDALClose() before GDALDeleteDataset(), and make sure 
that the handle to the dataset is no used afterwards of course. I mention that 
because I'm not sure what R_ClearExternalPtr() does.


> 
> Best wishes,
> 
> Roger
> 


-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list