[gdal-dev] memory leak in gdal program
jramm
jamessramm at gmail.com
Fri Aug 21 08:32:09 PDT 2015
I'm using GDAL 201 to iterate features in a geodatabase feature class and add
a new text field, whose value depends on the integer value in another
field.It gives a fairly large memory leak (approx 1GB for every 1m features
iterated). I'm not sure where the leak is....any ideas?The full code:int
main(int argc, char *argv[]){ // Get the input arguments char *path =
argv[1]; char *layer = argv[2]; char *field = argv[3]; // Open the dataset
in update mode GDALAllRegister(); GDALDatasetH hDS; hDS = GDALOpenEx(path,
GDAL_OF_VECTOR | GDAL_OF_UPDATE , NULL, NULL, NULL); if( hDS == NULL ) {
printf( "Open failed.\n" ); exit( 1 ); } // Get the layer OGRLayerH hLayer;
hLayer = GDALDatasetGetLayerByName(hDS, layer); OGRFeatureDefnH hFDefn =
OGR_L_GetLayerDefn(hLayer); // Get the field index int index =
OGR_FD_GetFieldIndex(hFDefn, field); // Create the new field OGRFieldDefnH
hFieldDefn; hFieldDefn = OGR_Fld_Create("depth_band", OFTString);
OGR_Fld_SetWidth(hFieldDefn, 32); if( OGR_L_CreateField( hLayer,
hFieldDefn, TRUE ) != OGRERR_NONE ) { printf( "Creating depth_band
field failed.\n" ); exit( 1 ); } OGR_Fld_Destroy(hFieldDefn);
int value; // Field value char depth_band[32]; //New attribute // Loop
through all features OGRFeatureH hFeature; OGR_L_ResetReading(hLayer); int
count = 0; while( (hFeature = OGR_L_GetNextFeature(hLayer)) != NULL) { //
Get the depth band value and map it to the depth band description text
value = OGR_F_GetFieldAsInteger(hFeature, index); switch(value){ case 1:
depth_band = "x <= 0.3m"; break; case 2: depth_band = "0.3 < x <=
1m"; break; case 3: depth_band = "1 < x <= 3m"; break; case 4:
depth_band = "3 < x <= 6m"; break; case 5: depth_band = "6 < x <=
9m"; break; case 6: depth_band = "x > 9m"; break; } // Set the
new field value OGR_F_SetFieldString(hFeature,
OGR_F_GetFieldIndex(hFeature, "depth_band"), depth_band); count++;
printf("%d features processed\r", count); } GDALClose(hDS);
printf("\nProcessing complete!\n");}
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/memory-leak-in-gdal-program-tp5220559.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150821/ba0f6fe2/attachment.html>
More information about the gdal-dev
mailing list