Skip to content

Commit

Permalink
Merge pull request #11085 from OSGeo/backport-11055-to-release/3.10
Browse files Browse the repository at this point in the history
[Backport release/3.10] ESRIC: fix memory leak
  • Loading branch information
rouault authored Oct 22, 2024
2 parents 211fff6 + 619937a commit 9024fb3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions frmts/esric/esric_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ class ESRICProxyRasterBand final : public GDALProxyRasterBand
class ESRICProxyDataset final : public GDALProxyDataset
{
private:
// m_poSrcDS must be placed before m_poUnderlyingDS for proper destruction
// as m_poUnderlyingDS references m_poSrcDS
std::unique_ptr<GDALDataset> m_poSrcDS{};
std::unique_ptr<GDALDataset> m_poUnderlyingDS{};
CPLStringList m_aosFileList{};

Expand All @@ -584,8 +587,9 @@ class ESRICProxyDataset final : public GDALProxyDataset
}

public:
ESRICProxyDataset(GDALDataset *poUnderlyingDS, const char *pszDescription)
: m_poUnderlyingDS(poUnderlyingDS)
ESRICProxyDataset(GDALDataset *poSrcDS, GDALDataset *poUnderlyingDS,
const char *pszDescription)
: m_poSrcDS(poSrcDS), m_poUnderlyingDS(poUnderlyingDS)
{
nRasterXSize = poUnderlyingDS->GetRasterXSize();
nRasterYSize = poUnderlyingDS->GetRasterYSize();
Expand Down Expand Up @@ -744,15 +748,15 @@ GDALDataset *ECDataset::Open(GDALOpenInfo *poOpenInfo,
aosOptions.AddString(CPLSPrintf("BLOCKYSIZE=%d", ds->TSZ));
auto psOptions =
GDALTranslateOptionsNew(aosOptions.List(), nullptr);
auto hDS = GDALTranslate("", GDALDataset::ToHandle(ds.release()),
auto hDS = GDALTranslate("", GDALDataset::ToHandle(ds.get()),
psOptions, nullptr);
GDALTranslateOptionsFree(psOptions);
if (!hDS)
{
return nullptr;
}
return new ESRICProxyDataset(GDALDataset::FromHandle(hDS),
pszDescription);
return new ESRICProxyDataset(
ds.release(), GDALDataset::FromHandle(hDS), pszDescription);
}
return ds.release();
}
Expand Down

0 comments on commit 9024fb3

Please sign in to comment.