Skip to content

Commit

Permalink
Geoconcept: fix potential double-free on creation error code
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 24, 2025
1 parent 6cdae8b commit a9854d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ GCSysCoord GCSRSAPI_CALL1(*)
const GCSpheroidInfo *ell = NULL;
const GCDatumInfo *datum = NULL;
const GCProjectionInfo *gcproj = NULL;
double a, rf, f, p[7];
double a, rf, f, p[7] = {0, 0, 0, 0, 0, 0, 0};
GCSysCoord *syscoord = NULL;

if (!poSR)
Expand Down
34 changes: 16 additions & 18 deletions ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,30 +613,28 @@ void OGRGeoconceptLayer::SetSpatialRef(OGRSpatialReference *poSpatialRef)

{
OGRSpatialReference *poSRS = GetSpatialRef();
/*-----------------------------------------------------------------
* Keep a copy of the OGRSpatialReference...
* Note: we have to take the reference count into account...
*----------------------------------------------------------------*/
if (poSRS && poSRS->Dereference() == 0)
delete poSRS;

if (!poSpatialRef)
return;

poSRS = poSpatialRef->Clone();
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
GCExportFileH *hGXT = GetSubTypeGCHandle_GCIO(_gcFeature);
if (!hGXT)
if (hGXT)
{
delete poSRS;
return;
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
if (Meta)
{
if (poSRS)
poSRS->Release();
SetMetaSRS_GCIO(Meta, nullptr);
}
else
return;
}
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
if (!Meta)
else
{
delete poSRS;
return;
}

poSRS = poSpatialRef->Clone();
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
GCSysCoord *os = GetMetaSysCoord_GCIO(Meta);
GCSysCoord *ns = OGRSpatialReference2SysCoord_GCSRS(
reinterpret_cast<OGRSpatialReferenceH>(poSRS));
Expand All @@ -648,7 +646,7 @@ void OGRGeoconceptLayer::SetSpatialRef(OGRSpatialReference *poSpatialRef)
CPLError(CE_Warning, CPLE_AppDefined,
"Can't change SRS on Geoconcept layers.\n");
DestroySysCoord_GCSRS(&ns);
delete poSRS;
poSRS->Release();
return;
}

Expand Down

0 comments on commit a9854d1

Please sign in to comment.