Skip to content

Commit

Permalink
Use GDALDatasetUniquePtr
Browse files Browse the repository at this point in the history
* The raw pointer was never deleted and was a memory leak

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Jan 17, 2024
1 parent 341aaa5 commit 8453d6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/grid_map_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8453d6e

Please sign in to comment.