From ff3bc0c164f17b09ecc9e705e843bb81f309a2a9 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 14 Jun 2017 20:40:52 +0100 Subject: [PATCH] Add cleanup code to LIDAR resampling --- inputs.cc | 11 ++++++++++- tiles.cc | 10 ++++++++++ tiles.hh | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/inputs.cc b/inputs.cc index 995e3c4..9017348 100644 --- a/inputs.cc +++ b/inputs.cc @@ -304,7 +304,6 @@ int loadLIDAR(char *filenames, int resample) fprintf(stderr, "Overflow %zu\n",i); continue; } - // fprintf(stderr,"dest:%p src:%p\n", dest_addr, src_addr); memcpy( dest_addr, src_addr, tiles[i].width * sizeof(short) ); } } @@ -349,6 +348,16 @@ int loadLIDAR(char *filenames, int resample) if (debug) fprintf(stderr, "fc %d WIDTH %d HEIGHT %d ippd %d minN %.5f maxN %.5f minW %.5f maxW %.5f avgCellsize %.5f\n", fc, width, height, ippd,min_north,max_north,min_west,max_west,avgCellsize); + +cleanup: + + if ( tiles != NULL ) { + for (size_t i = 0; i < fc; i++) { + tile_destroy(&tiles[i]); + } + } + free(tiles); + return 0; } diff --git a/tiles.cc b/tiles.cc index 05912af..f81bcb7 100644 --- a/tiles.cc +++ b/tiles.cc @@ -233,3 +233,13 @@ int tile_resize(tile_t* tile, int resolution){ fprintf(stderr, "Resampling: Current %dm Desired %dm Scale %d\n", current_res, resolution, scaling_factor); return tile_rescale(tile, scaling_factor); } + +/* + * tile_destroy + * This function simply destroys any data associated with a tile + */ +void tile_destroy(tile_t* tile){ + if (tile->data != NULL) + free(tile->data); +} + diff --git a/tiles.hh b/tiles.hh index 8bb0caf..a2d25f4 100644 --- a/tiles.hh +++ b/tiles.hh @@ -42,5 +42,6 @@ typedef struct _tile_t{ int tile_load_lidar(tile_t*, char *); int tile_rescale(tile_t *, float); +void tile_destroy(tile_t *); #endif \ No newline at end of file