Changes between Initial Version and Version 1 of Ticket #6384


Ignore:
Timestamp:
Feb 28, 2016, 4:02:05 AM (8 years ago)
Author:
mcserep
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #6384

    • Property Component OGR_SRSdefault
    • Property Summary Deleting OGRSpatialReference object runs into segmentation faultAccess violation in Visual Studio when compiled with Multi-threaded Debug DLL
  • Ticket #6384 – Description

    initial v1  
    1 I am trying to get the spatial reference system from a `GDALDataset`, work with it and then free it properly as follows:
    2 
     1I 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:
    32{{{
    43#!cpp
    5 GDALDataset* dataset = /* ... */;
    6 OGRSpatialReference* reference = new OGRSpatialReference(dataset->GetProjectionRef());
     4#include <ogr_geometry.h>
    75
    8 /* work on reference, everything seems OK here */
    9 
    10 delete reference; // segmentation fault
    11 GDALClose(dataset);
     6int main(int argc, char* argv[])
     7{
     8    OGRPoint *point = new OGRPoint;
     9    delete point; // segmentation fault
     10    return 0;
     11}
    1212}}}
    1313
    14 My problem is that the deletion of the `reference` object runs into a segmentation fault, regardless whether the dataset contained a valid ''SRS'' or just returned an empty string.
     14Similar 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.
    1515
    16 Basically, creating an `OGRSpatialReference` with its default constructor and then freeing it, results with the very same issue:
     16The 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++`.
    1717
     18The callstack is the following:
    1819{{{
    19 #!cpp
    20 OGRSpatialReference* reference = new OGRSpatialReference();
    21 delete reference; // segmentation fault
     20ntdll.dll!_RtlReportCriticalFailure@8() Unknown
     21ntdll.dll!_RtlpHeapHandleError@4()      Unknown
     22ntdll.dll!_RtlpLogHeapFailure@24()      Unknown
     23ntdll.dll!RtlFreeHeap() Unknown
     24AcLayers.dll!6d7158bf() Unknown
     25[Frames below may be incorrect and/or missing, no symbols loaded for AcLayers.dll]     
     26gdal201.dll!0f87bdbd()  Unknown
     27TestProject.exe!main(int argc, char * * argv) Line 7    C++
     28[External Code]
    2229}}}
    23 
    24 I am using GDAL 2.1.0dev, prebuilt libraries and headers downloaded from [http://gisinternals.com/ gisinternals.com] for Windows.