Skip to content

Commit a9854d1

Browse files
committed
Geoconcept: fix potential double-free on creation error code
Fixes https://issues.oss-fuzz.com/issues/391921977
1 parent 6cdae8b commit a9854d1

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

ogr/ogrsf_frmts/geoconcept/geoconcept_syscoord.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ GCSysCoord GCSRSAPI_CALL1(*)
877877
const GCSpheroidInfo *ell = NULL;
878878
const GCDatumInfo *datum = NULL;
879879
const GCProjectionInfo *gcproj = NULL;
880-
double a, rf, f, p[7];
880+
double a, rf, f, p[7] = {0, 0, 0, 0, 0, 0, 0};
881881
GCSysCoord *syscoord = NULL;
882882

883883
if (!poSR)

ogr/ogrsf_frmts/geoconcept/ogrgeoconceptlayer.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -613,30 +613,28 @@ void OGRGeoconceptLayer::SetSpatialRef(OGRSpatialReference *poSpatialRef)
613613

614614
{
615615
OGRSpatialReference *poSRS = GetSpatialRef();
616-
/*-----------------------------------------------------------------
617-
* Keep a copy of the OGRSpatialReference...
618-
* Note: we have to take the reference count into account...
619-
*----------------------------------------------------------------*/
620-
if (poSRS && poSRS->Dereference() == 0)
621-
delete poSRS;
622-
623-
if (!poSpatialRef)
624-
return;
625616

626-
poSRS = poSpatialRef->Clone();
627-
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
628617
GCExportFileH *hGXT = GetSubTypeGCHandle_GCIO(_gcFeature);
629-
if (!hGXT)
618+
if (hGXT)
630619
{
631-
delete poSRS;
632-
return;
620+
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
621+
if (Meta)
622+
{
623+
if (poSRS)
624+
poSRS->Release();
625+
SetMetaSRS_GCIO(Meta, nullptr);
626+
}
627+
else
628+
return;
633629
}
634-
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
635-
if (!Meta)
630+
else
636631
{
637-
delete poSRS;
638632
return;
639633
}
634+
635+
poSRS = poSpatialRef->Clone();
636+
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
637+
GCExportFileMetadata *Meta = GetGCMeta_GCIO(hGXT);
640638
GCSysCoord *os = GetMetaSysCoord_GCIO(Meta);
641639
GCSysCoord *ns = OGRSpatialReference2SysCoord_GCSRS(
642640
reinterpret_cast<OGRSpatialReferenceH>(poSRS));
@@ -648,7 +646,7 @@ void OGRGeoconceptLayer::SetSpatialRef(OGRSpatialReference *poSpatialRef)
648646
CPLError(CE_Warning, CPLE_AppDefined,
649647
"Can't change SRS on Geoconcept layers.\n");
650648
DestroySysCoord_GCSRS(&ns);
651-
delete poSRS;
649+
poSRS->Release();
652650
return;
653651
}
654652

0 commit comments

Comments
 (0)