Opened 8 years ago

Closed 7 years ago

#6384 closed defect (fixed)

Access violation in Visual Studio when compiled with Multi-threaded Debug DLL

Reported by: mcserep Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: svn-trunk
Severity: normal Keywords:
Cc:

Description (last modified by mcserep)

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]	

Change History (4)

comment:1 by mcserep, 8 years ago

Component: OGR_SRSdefault
Description: modified (diff)
Summary: Deleting OGRSpatialReference object runs into segmentation faultAccess violation in Visual Studio when compiled with Multi-threaded Debug DLL

comment:2 by mcserep, 8 years ago

After some searching I realized that this issue have been raised multiple times already:

  • #3346 (Debug build of static library crashes on Windows)
  • #4291 (Debug version of app with GDAL lib - linker problem)
  • #540 (Missing /MDd switch for debug build in nmake.opt)
  • #1647 (CPLString methods produce objects which crosses library boundaries)

The issue was not fixed and since the default runtime library linking in Visual Studio for Debug configuration is /MDd, it can easily cause further problems to others too. I think when the library is compiled with the DEBUG flag, it should use /MDd instead of /MD.

comment:3 by Even Rouault, 8 years ago

Milestone: 2.1.0

Unmilestoning

comment:4 by Even Rouault, 7 years ago

Resolution: fixed
Status: newclosed

In 40242:

nmake.opt: use /MDd for OPTFLAGS for DEBUG=1 builds (fixes #7059, fixes #6384, fixes #4291, fixes #3346, fixes #1647, fixes #540)

Note: See TracTickets for help on using tickets.