From 46786bb6f19039898ae590ff7809f703b40e0b30 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 28 Jan 2024 20:54:57 +0100 Subject: [PATCH 1/2] gdaltindex: fix potential memory leak (CID 1533976) --- apps/gdaltindex_lib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gdaltindex_lib.cpp b/apps/gdaltindex_lib.cpp index 2f30395bb587..59a6bbe124eb 100644 --- a/apps/gdaltindex_lib.cpp +++ b/apps/gdaltindex_lib.cpp @@ -1000,13 +1000,13 @@ GDALDatasetH GDALTileIndex(const char *pszDest, int nSrcCount, if (poSrcSRS->exportToProj4(&pszProj4) == OGRERR_NONE) { poFeature->SetField(i_SrcSRSName, pszProj4); - CPLFree(pszProj4); } else { poFeature->SetField(i_SrcSRSName, poSrcDS->GetProjectionRef()); } + CPLFree(pszProj4); } } else if (psOptions->eSrcSRSFormat == FORMAT_WKT) @@ -1031,8 +1031,8 @@ GDALDatasetH GDALTileIndex(const char *pszDest, int nSrcCount, if (poSrcSRS->exportToProj4(&pszProj4) == OGRERR_NONE) { poFeature->SetField(i_SrcSRSName, pszProj4); - CPLFree(pszProj4); } + CPLFree(pszProj4); } else if (psOptions->eSrcSRSFormat == FORMAT_EPSG) { From 43dd934dc946536bc5a20fa8b27905c3597a1499 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 28 Jan 2024 20:55:14 +0100 Subject: [PATCH 2/2] GTIFMemBufFromSRS: fix potential nullptr deref (CID 1533975) --- frmts/gtiff/gt_wkt_srs.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/frmts/gtiff/gt_wkt_srs.cpp b/frmts/gtiff/gt_wkt_srs.cpp index 9492d79a4df7..75662539444a 100644 --- a/frmts/gtiff/gt_wkt_srs.cpp +++ b/frmts/gtiff/gt_wkt_srs.cpp @@ -3703,20 +3703,22 @@ CPLErr GTIFMemBufFromSRS(OGRSpatialReferenceH hSRS, { hGTIF = GTIFNew(hTIFF); if (hGTIF) + { GTIFAttachPROJContext(hGTIF, OSRGetProjTLSContext()); - if (hSRS != nullptr) - GTIFSetFromOGISDefnEx(hGTIF, hSRS, GEOTIFF_KEYS_STANDARD, - GEOTIFF_VERSION_1_0); + if (hSRS != nullptr) + GTIFSetFromOGISDefnEx(hGTIF, hSRS, GEOTIFF_KEYS_STANDARD, + GEOTIFF_VERSION_1_0); - if (bPixelIsPoint) - { - GTIFKeySet(hGTIF, GTRasterTypeGeoKey, TYPE_SHORT, 1, - RasterPixelIsPoint); - } + if (bPixelIsPoint) + { + GTIFKeySet(hGTIF, GTRasterTypeGeoKey, TYPE_SHORT, 1, + RasterPixelIsPoint); + } - GTIFWriteKeys(hGTIF); - GTIFFree(hGTIF); + GTIFWriteKeys(hGTIF); + GTIFFree(hGTIF); + } } /* -------------------------------------------------------------------- */