Skip to content

Commit aaffb5c

Browse files
authored
Use GDALDatasetUniquePtr (#44)
* The raw pointer was never deleted and was a memory leak Signed-off-by: Ryan Friedman <[email protected]>
1 parent 14cfed1 commit aaffb5c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/grid_map_geo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool GridMapGeo::Load(const std::string &map_path, bool algin_terrain, const std
7373

7474
bool GridMapGeo::initializeFromGeotiff(const std::string &path, bool align_terrain) {
7575
GDALAllRegister();
76-
GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly);
76+
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
7777
if (!dataset) {
7878
std::cout << "Failed to open" << std::endl;
7979
return false;
@@ -171,7 +171,7 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path, bool align_terra
171171

172172
bool GridMapGeo::addColorFromGeotiff(const std::string &path) {
173173
GDALAllRegister();
174-
GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly);
174+
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
175175
if (!dataset) {
176176
std::cout << "Failed to open" << std::endl;
177177
return false;
@@ -232,7 +232,7 @@ bool GridMapGeo::addColorFromGeotiff(const std::string &path) {
232232

233233
bool GridMapGeo::addLayerFromGeotiff(const std::string &layer_name, const std::string &path) {
234234
GDALAllRegister();
235-
GDALDataset *dataset = (GDALDataset *)GDALOpen(path.c_str(), GA_ReadOnly);
235+
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
236236
if (!dataset) {
237237
std::cout << "Failed to open" << std::endl;
238238
return false;

0 commit comments

Comments
 (0)