Opened 14 years ago
Closed 14 years ago
#3529 closed defect (fixed)
Crash on memory release in CSharp wrapper
Reported by: | joker99 | Owned by: | tamas |
---|---|---|---|
Priority: | normal | Milestone: | 1.7.2 |
Component: | CSharpBindings | Version: | 1.7.1 |
Severity: | major | Keywords: | |
Cc: |
Description
When using SpatialReference.ExportToWkt method from c# wrapper, there is either crash or stack overflow exception or AccessViolation exception.
Use this code to reproduce:
class Program { static void Main(string[] args) { Ogr.RegisterAll(); using (var sourceDS = Ogr.Open(<path_to_feature_layer_with_srs>, 0)) { var sourceLayer = sourceDS.GetLayerByIndex(0); using (var sourceSRS = sourceLayer.GetSpatialRef()) { if (sourceSRS != null) { string wkt = null; Console.WriteLine("Getting projeciton wkt"); sourceSRS.ExportToWkt(out wkt); Console.WriteLine("Projection wkt:" + wkt); } } } } }
The bug happens because the memory returned from GDAL is freed using free
function and not CPLFree
in swig generated CSharp_SpatialReference_ExportToWkt
function.
Change History (5)
comment:1 by , 14 years ago
Component: | SWIG (all bindings) → CSharpBindings |
---|---|
Owner: | changed from | to
comment:2 by , 14 years ago
I tried
using (var sourceDS = Ogr.Open(<shape_file>, 0)) { var sourceLayer = sourceDS.GetLayerByIndex(0); using (var f = sourceLayer.GetFeature(0)) { using (var geom = f.GetGeometryRef()) { int i = 0; while (true) { string x; geom.ExportToWkt(out x); i++; if (i % 10000 == 0) Console.WriteLine(i); } } } }
and it had stable memory usage on my machine for about 1 million iterations.
comment:5 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Tamas,
I have confirmed the issue when running apps/WKT2WKB.cs with GDAL compiled with uncommented #define DEBUG_VSIMALLOC in port/cpl_vsisimple.cpp, which is a good way of checking consistant pairing of CPL/VSI memory allocation routines.
seems to do the trick, but I let you check & apply.
By the way, I'm wondering if there are not memory leaks in the csharp bindings with functions using 'out string'. I've tried the following and memory usage grows continuously :
or
But perhaps I'm doing something wrong or forgetting an explicit deallocation. I'm less that a newbee in csharp ;-)