Changes between Initial Version and Version 1 of Ticket #6384
- Timestamp:
- Feb 28, 2016, 4:02:05 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #6384
- Property Component OGR_SRS → default
- Property Summary Deleting OGRSpatialReference object runs into segmentation fault → Access 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 1 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: 3 2 {{{ 4 3 #!cpp 5 GDALDataset* dataset = /* ... */; 6 OGRSpatialReference* reference = new OGRSpatialReference(dataset->GetProjectionRef()); 4 #include <ogr_geometry.h> 7 5 8 /* work on reference, everything seems OK here */ 9 10 delete reference; // segmentation fault 11 GDALClose(dataset); 6 int main(int argc, char* argv[]) 7 { 8 OGRPoint *point = new OGRPoint; 9 delete point; // segmentation fault 10 return 0; 11 } 12 12 }}} 13 13 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.14 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. 15 15 16 Basically, creating an `OGRSpatialReference` with its default constructor and then freeing it, results with the very same issue: 16 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++`. 17 17 18 The callstack is the following: 18 19 {{{ 19 #!cpp 20 OGRSpatialReference* reference = new OGRSpatialReference(); 21 delete reference; // segmentation fault 20 ntdll.dll!_RtlReportCriticalFailure@8() Unknown 21 ntdll.dll!_RtlpHeapHandleError@4() Unknown 22 ntdll.dll!_RtlpLogHeapFailure@24() Unknown 23 ntdll.dll!RtlFreeHeap() Unknown 24 AcLayers.dll!6d7158bf() Unknown 25 [Frames below may be incorrect and/or missing, no symbols loaded for AcLayers.dll] 26 gdal201.dll!0f87bdbd() Unknown 27 TestProject.exe!main(int argc, char * * argv) Line 7 C++ 28 [External Code] 22 29 }}} 23 24 I am using GDAL 2.1.0dev, prebuilt libraries and headers downloaded from [http://gisinternals.com/ gisinternals.com] for Windows.