[gdal-dev] OGR DeleteFeature throws memory exception

Brad Grinstead bgrinstead at iavo-rs.com
Wed Nov 5 11:01:00 EST 2008


I am wondering if someone has experienced a memory access violation when attempting to delete OGRFeatures.  I am running the latest build off the trunk and have been able to find no information regarding this error.

Basically, I am following the OGR API tutorial format, with a wrapper for the OGR functionality.  The code looks like this:

 
for (int j = 0; j < featureCount; j++)
{
    if ((feature = layer.GetNextFeature()) == null)
        continue;
    geometry = feature.GetGeometry();
    if (geometry != null)
    {
        geoType = geometry.GetGeometryType();
        
        //PROCESS GEOMETRY
    }
 
    feature.Dispose();
}
 
 
 
and the dispose function for the feature's wrapper is:
 
!Feature()
{
	if (disposed)
		return;
 
	try 
	{
		OGRFeature::DestroyFeature(this->feat);
	}
	catch (System::Exception^)
	{
		Console::WriteLine("AVE:Feature");
	}
	disposed = true;
}


On some shapefiles (not all) the DestroyFeature function throws an AccessViolationException.  When run through the ingestion loop, a number of these are thrown before the application crashes.  If I comment out the DestroyFeature call, the ingestion succeeds, but I think it is opening a hole for memory leaks.  Sort of a "damned if you do, damned if you don't" situation.
 


Thanks in advance,

Brad G.





More information about the gdal-dev mailing list