Opened 12 years ago
Closed 12 years ago
#4749 closed defect (fixed)
Memory leaks when using SQL queries with shapefiles
Reported by: | pierluigiguasqui | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 1.9.2 |
Component: | OGR_SF | Version: | 1.9.0 |
Severity: | normal | Keywords: | shapefile |
Cc: |
Description
Hello,
I am experiencing a big memory allocation (with no subsequent memory release) when using SQL queries with shapefiles. This is a sample code that triggers the problem:
OGRRegisterAll(); int loop_i = 1; while ( true ) {
fprintf( stdout, "* Loop %d... ", loop_i++ ); fflush( stdout );
opening shapefile data source const char *fname = "path/to/shapefile.shp"; OGRDataSource *poDS; poDS = OGRSFDriverRegistrar::Open( fname, FALSE );
if( poDS == NULL ) {
fprintf( stderr, "%s: could not open input file\n", fname ); return -1;
}
creating the spatial filter OGRLineString regionPolygon; OGRRawPoint *pointsList = new OGRRawPoint[5]; pointsList[0].x = -180; pointsList[0].y = 90; pointsList[1].x = 180; pointsList[1].y = 90; pointsList[2].x = 180; pointsList[2].y = -90; pointsList[3].x = -180; pointsList[3].y = -90; pointsList[4].x = -180; pointsList[4].y = 90; regionPolygon.setPoints(5, pointsList); delete[] pointsList;
executing the query const char *query = "SELECT * FROM table_name WHERE some_field LIKE '%bla%' ORDER BY some_other_field"; OGRLayer *rs = poDS->ExecuteSQL( query, ®ionPolygon, NULL );
releasing memory poDS->ReleaseResultSet( rs ); OGRDataSource::DestroyDataSource( poDS );
fprintf( stdout, "done\n" ); fflush( stdout );
}
Memory allocation happens in "ExecuteSQL" and there is no deallocation when calling "ReleaseResultSet", as I would expect. With a 100.000 records shapefile and just 3 loops I can get my process to allocate almost 1 GByte of memory and allocation keeps increasing at each iteration.
I tried different test cases and I think I can jump to the conclusion that the memory leak happens if there is a spatial filter together with an SQL query that contains a "WHERE" clause and an "ORDER BY" clause. If I leave all other things unchanged and just remove the use of the spatial filter I do not see any memory leak, as well as if I try the SQL query without the "WHERE" clause or the "ORDER BY" clause.
I am using GDAL 1.9.1 under Windows platform.
Change History (1)
comment:1 by , 12 years ago
Component: | default → OGR_SF |
---|---|
Keywords: | shapefile added |
Milestone: | → 1.9.2 |
Resolution: | → fixed |
Status: | new → closed |
Version: | 1.9.1 → 1.9.0 |
r24686 /trunk/gdal/ogr/ogrsf_frmts/shape/shape2ogr.cpp: Shapefile: fix memory leak when IsGeometryIgnored() is set (#4749)
r24687 /branches/1.9/gdal/ogr/ogrsf_frmts/shape/shape2ogr.cpp: Shapefile: fix memory leak when IsGeometryIgnored() is set (#4749)