From 8453d6e384ad3126b279dca2dc621fd42016d1b2 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Tue, 16 Jan 2024 21:07:35 -0700 Subject: [PATCH] Use GDALDatasetUniquePtr * The raw pointer was never deleted and was a memory leak Signed-off-by: Ryan Friedman --- src/grid_map_geo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/grid_map_geo.cpp b/src/grid_map_geo.cpp index 82f617e..8848e0a 100644 --- a/src/grid_map_geo.cpp +++ b/src/grid_map_geo.cpp @@ -58,7 +58,7 @@ bool GridMapGeo::Load(const std::string &map_path, bool algin_terrain, const std bool GridMapGeo::initializeFromGeotiff(const std::string &path, bool align_terrain) { GDALAllRegister(); - GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly); + const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly))); if (!dataset) { std::cout << "Failed to open" << std::endl; return false; @@ -149,7 +149,7 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path, bool align_terra bool GridMapGeo::addColorFromGeotiff(const std::string &path) { GDALAllRegister(); - GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly); + const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly))); if (!dataset) { std::cout << "Failed to open" << std::endl; return false; @@ -210,7 +210,7 @@ bool GridMapGeo::addColorFromGeotiff(const std::string &path) { bool GridMapGeo::addLayerFromGeotiff(const std::string &layer_name, const std::string &path) { GDALAllRegister(); - GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly); + const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly))); if (!dataset) { std::cout << "Failed to open" << std::endl; return false;