Skip to content

Commit

Permalink
gdal raster calc: avoid leaking SRS
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Feb 17, 2025
1 parent 0e67eb9 commit d1807e4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/gdalalg_raster_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ struct SourceProperties
int nX{0};
int nY{0};
std::array<double, 6> gt{};
OGRSpatialReference *srs{nullptr};
std::unique_ptr<OGRSpatialReference, OGRSpatialReferenceReleaser> srs{
nullptr};
};

static std::optional<SourceProperties>
Expand Down Expand Up @@ -136,7 +137,7 @@ UpdateSourceProperties(SourceProperties &out, const std::string &dsn,
if (options.checkSRS && out.srs)
{
const OGRSpatialReference *srs = ds->GetSpatialRef();
srsMismatch = srs && !srs->IsSame(out.srs);
srsMismatch = srs && !srs->IsSame(out.srs.get());
}
}

Expand Down Expand Up @@ -461,7 +462,8 @@ GDALCalcCreateVRTDerived(const std::vector<std::string> &inputs,
out.nX = ds->GetRasterXSize();
out.nY = ds->GetRasterYSize();
out.nBands = 1;
out.srs = ds->GetSpatialRef() ? ds->GetSpatialRef()->Clone() : nullptr;
out.srs.reset(ds->GetSpatialRef() ? ds->GetSpatialRef()->Clone()
: nullptr);
ds->GetGeoTransform(out.gt.data());
}

Expand All @@ -476,7 +478,7 @@ GDALCalcCreateVRTDerived(const std::vector<std::string> &inputs,
auto props = UpdateSourceProperties(out, dsn, options);
if (props.has_value())
{
sourceProps[source_name] = props.value();
sourceProps[source_name] = std::move(props.value());
}
else
{
Expand All @@ -503,7 +505,7 @@ GDALCalcCreateVRTDerived(const std::vector<std::string> &inputs,
ds->SetGeoTransform(out.gt.data());
if (out.srs)
{
ds->SetSpatialRef(OGRSpatialReference::FromHandle(out.srs));
ds->SetSpatialRef(OGRSpatialReference::FromHandle(out.srs.get()));
}

return ds;
Expand Down

0 comments on commit d1807e4

Please sign in to comment.