I am building an application using the GDAL/OGR library and have faced a really strange issue, namely getting an access violation error when running my program compiled with Multi-threaded Debug DLL (/MDd
) runtime library option. The following example is a minimal sample to demonstrate the problem:
#include <ogr_geometry.h>
int main(int argc, char* argv[])
{
OGRPoint *point = new OGRPoint;
delete point; // segmentation fault
return 0;
}
Similar problem occurs with other OGR types in the GDAL/OGR library, so it is not related to the OGRPoint
class. However there is no issue when the memory is allocated on the stack and not on the heap.
The code executes fine when I use the Multi-threaded DLL configuration instead. (So basically Release mode is good, but Debug mode runs into the mentioned access violation error.) The program also runs fine on Linux compiled with g++
.
The callstack is the following:
ntdll.dll!_RtlReportCriticalFailure@8() Unknown
ntdll.dll!_RtlpHeapHandleError@4() Unknown
ntdll.dll!_RtlpLogHeapFailure@24() Unknown
ntdll.dll!RtlFreeHeap() Unknown
AcLayers.dll!6d7158bf() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for AcLayers.dll]
gdal201.dll!0f87bdbd() Unknown
TestProject.exe!main(int argc, char * * argv) Line 7 C++
[External Code]
Any ideas on what is causing this problem?