Skip to content

Commit

Permalink
SOSI: fix false-positive CodeQL warning about potential double free (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 18, 2024
1 parent 830a7f6 commit 33d33d3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions ogr/ogrsf_frmts/sosi/ogrsosilayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
}

/* get Feature from fyba, according to feature definition */
OGRGeometry *poGeom = nullptr;
std::unique_ptr<OGRGeometry> poGeom;
OGRwkbGeometryType oGType = wkbUnknown;

switch (nName)
Expand Down Expand Up @@ -384,7 +384,7 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
nRefCount = LC_GetRefFlate(&oGrfStat, GRF_INDRE,
&nRefNr, &nRefStatus, 1);
}
poGeom = poLy.release();
poGeom = std::move(poLy);
}
break;
}
Expand All @@ -404,10 +404,10 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
// return NULL;
break;
}
OGRLineString *poCurve =
const OGRLineString *poCurve =
poParent->papoBuiltGeometries[oNextSerial.lNr]
->toLineString();
poGeom = poCurve->clone();
poGeom.reset(poCurve->clone());
break;
}
case L_TEKST:
Expand All @@ -424,10 +424,10 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
// return NULL;
break;
}
OGRMultiPoint *poMP =
const OGRMultiPoint *poMP =
poParent->papoBuiltGeometries[oNextSerial.lNr]
->toMultiPoint();
poGeom = poMP->clone();
poGeom.reset(poMP->clone());
break;
}
case L_SYMBOL:
Expand All @@ -450,9 +450,9 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
// return NULL;
break;
}
OGRPoint *poPoint =
const OGRPoint *poPoint =
poParent->papoBuiltGeometries[oNextSerial.lNr]->toPoint();
poGeom = poPoint->clone();
poGeom.reset(poPoint->clone());
break;
}
case L_DEF: /* skip user definitions and headers here */
Expand All @@ -472,7 +472,6 @@ OGRFeature *OGRSOSILayer::GetNextFeature()
continue; /* skipping L_HODE and unrecognized groups */
if (oGType != poFeatureDefn->GetGeomType())
{
delete poGeom;
continue; /* skipping features that are not the correct geometry */
}

Expand Down Expand Up @@ -562,7 +561,7 @@ OGRFeature *OGRSOSILayer::GetNextFeature()

poGeom->assignSpatialReference(poParent->poSRS);

poFeature->SetGeometryDirectly(poGeom);
poFeature->SetGeometryDirectly(poGeom.release());
poFeature->SetFID(nNextFID++);

/* Loop until we have a feature that matches the definition */
Expand Down

0 comments on commit 33d33d3

Please sign in to comment.