Skip to content
Snippets Groups Projects
Commit 21039eb8 authored by Julien Malik's avatar Julien Malik
Browse files

BUG: Avoid cross heap pb when writing vector data on windows

parent cc9b60f0
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ OGRIOHelper<TVectorData> ...@@ -72,7 +72,7 @@ OGRIOHelper<TVectorData>
LinePointerType line = LineType::New(); LinePointerType line = LineType::New();
OGRPoint * ogrTmpPoint = new OGRPoint(); OGRPoint * ogrTmpPoint = (OGRPoint *)OGRGeometryFactory::createGeometry(wkbPoint);
for (int pIndex = 0; pIndex < ogrLine->getNumPoints(); ++pIndex) for (int pIndex = 0; pIndex < ogrLine->getNumPoints(); ++pIndex)
{ {
...@@ -95,7 +95,7 @@ OGRIOHelper<TVectorData> ...@@ -95,7 +95,7 @@ OGRIOHelper<TVectorData>
line->AddVertex(vertex); line->AddVertex(vertex);
} }
delete ogrTmpPoint; OGRGeometryFactory::destroyGeometry(ogrTmpPoint);
DataNodePointerType node = DataNodeType::New(); DataNodePointerType node = DataNodeType::New();
node->SetLine(line); node->SetLine(line);
...@@ -116,8 +116,7 @@ OGRIOHelper<TVectorData> ...@@ -116,8 +116,7 @@ OGRIOHelper<TVectorData>
itkGenericExceptionMacro(<< "Failed to convert OGRGeometry to OGRPolygon"); itkGenericExceptionMacro(<< "Failed to convert OGRGeometry to OGRPolygon");
} }
OGRPoint * ogrTmpPoint = new OGRPoint(); OGRPoint * ogrTmpPoint = (OGRPoint *)OGRGeometryFactory::createGeometry(wkbPoint);
OGRLinearRing * ogrRing = ogrPolygon->getExteriorRing(); OGRLinearRing * ogrRing = ogrPolygon->getExteriorRing();
PolygonPointerType extRing = PolygonType::New(); PolygonPointerType extRing = PolygonType::New();
...@@ -167,7 +166,7 @@ OGRIOHelper<TVectorData> ...@@ -167,7 +166,7 @@ OGRIOHelper<TVectorData>
intRings->PushBack(ring); intRings->PushBack(ring);
} }
delete ogrTmpPoint; OGRGeometryFactory::destroyGeometry(ogrTmpPoint);
DataNodePointerType node = DataNodeType::New(); DataNodePointerType node = DataNodeType::New();
node->SetPolygonExteriorRing(extRing); node->SetPolygonExteriorRing(extRing);
...@@ -726,8 +725,8 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -726,8 +725,8 @@ unsigned int OGRIOHelper<TVectorData>
{ {
//Build the ogrObject //Build the ogrObject
OGRPolygon * ogrPolygon = new OGRPolygon(); OGRPolygon * ogrPolygon = (OGRPolygon *)OGRGeometryFactory::createGeometry(wkbPolygon);
OGRLinearRing * ogrExternalRing = new OGRLinearRing(); OGRLinearRing * ogrExternalRing = (OGRLinearRing *)OGRGeometryFactory::createGeometry(wkbLinearRing);
VertexListConstPointerType vertexList = dataNode->GetPolygonExteriorRing()->GetVertexList(); VertexListConstPointerType vertexList = dataNode->GetPolygonExteriorRing()->GetVertexList();
typename VertexListType::ConstIterator vIt = vertexList->Begin(); typename VertexListType::ConstIterator vIt = vertexList->Begin();
...@@ -748,13 +747,13 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -748,13 +747,13 @@ unsigned int OGRIOHelper<TVectorData>
ogrPolygon->addRing(ogrExternalRing); ogrPolygon->addRing(ogrExternalRing);
// Close the polygon // Close the polygon
ogrPolygon->closeRings(); ogrPolygon->closeRings();
delete ogrExternalRing; OGRGeometryFactory::destroyGeometry(ogrExternalRing);
// Retrieving internal rings as well // Retrieving internal rings as well
for (typename PolygonListType::Iterator pIt = dataNode->GetPolygonInteriorRings()->Begin(); for (typename PolygonListType::Iterator pIt = dataNode->GetPolygonInteriorRings()->Begin();
pIt != dataNode->GetPolygonInteriorRings()->End(); ++pIt) pIt != dataNode->GetPolygonInteriorRings()->End(); ++pIt)
{ {
OGRLinearRing * ogrInternalRing = new OGRLinearRing(); OGRLinearRing * ogrInternalRing = (OGRLinearRing *)OGRGeometryFactory::createGeometry(wkbLinearRing);
vertexList = pIt.Get()->GetVertexList(); vertexList = pIt.Get()->GetVertexList();
vIt = vertexList->Begin(); vIt = vertexList->Begin();
...@@ -771,7 +770,7 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -771,7 +770,7 @@ unsigned int OGRIOHelper<TVectorData>
++vIt; ++vIt;
} }
ogrPolygon->addRing(ogrInternalRing); ogrPolygon->addRing(ogrInternalRing);
delete ogrInternalRing; OGRGeometryFactory::destroyGeometry(ogrInternalRing);
} }
//Save it in the structure //Save it in the structure
...@@ -796,7 +795,7 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -796,7 +795,7 @@ unsigned int OGRIOHelper<TVectorData>
ogrCollection->addGeometry(ogrPolygon); ogrCollection->addGeometry(ogrPolygon);
} }
delete ogrPolygon; OGRGeometryFactory::destroyGeometry(ogrPolygon);
break; break;
} }
case FEATURE_MULTIPOINT: case FEATURE_MULTIPOINT:
...@@ -806,8 +805,7 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -806,8 +805,7 @@ unsigned int OGRIOHelper<TVectorData>
itkExceptionMacro(<< "Problem while creating multipoint."); itkExceptionMacro(<< "Problem while creating multipoint.");
} }
OGRMultiPoint* ogrMultiPoint= new OGRMultiPoint(); OGRMultiPoint* ogrMultiPoint= (OGRMultiPoint* )OGRGeometryFactory::createGeometry(wkbMultiPoint);
OGRFeature *ogrFeature; OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
...@@ -831,8 +829,8 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -831,8 +829,8 @@ unsigned int OGRIOHelper<TVectorData>
} }
// Instanciate a new ogrMultiLineString feature // Instanciate a new ogrMultiLineString feature
OGRMultiLineString* ogrMultiLineString= new OGRMultiLineString(); OGRMultiLineString* ogrMultiLineString= (OGRMultiLineString* )OGRGeometryFactory::createGeometry(wkbMultiLineString);
OGRFeature *ogrFeature; OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
...@@ -855,14 +853,13 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -855,14 +853,13 @@ unsigned int OGRIOHelper<TVectorData>
} }
// Instanciate a new multipolygon feature // Instanciate a new multipolygon feature
OGRMultiPolygon* ogrMutliPolygon = new OGRMultiPolygon(); OGRMultiPolygon* ogrMultiPolygon= (OGRMultiPolygon* )OGRGeometryFactory::createGeometry(wkbMultiPolygon);
OGRFeature *ogrFeature; OGRFeature *ogrFeature;
ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn()); ogrFeature = OGRFeature::CreateFeature(ogrCurrentLayer->GetLayerDefn());
ogrFeature->SetField("Name", dataNode->GetNodeId()); ogrFeature->SetField("Name", dataNode->GetNodeId());
ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon); ogrFeature->GetDefnRef()->SetGeomType(wkbMultiPolygon);
ogrFeature->SetGeometry(ogrMutliPolygon); ogrFeature->SetGeometry(ogrMultiPolygon);
if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE) if (ogrCurrentLayer->CreateFeature(ogrFeature) != OGRERR_NONE)
{ {
...@@ -878,7 +875,7 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -878,7 +875,7 @@ unsigned int OGRIOHelper<TVectorData>
itkExceptionMacro(<< "Problem while creating collection."); itkExceptionMacro(<< "Problem while creating collection.");
} }
OGRGeometryCollection* ogrCollectionGeometry = new OGRGeometryCollection(); OGRGeometryCollection* ogrCollectionGeometry = (OGRGeometryCollection* )OGRGeometryFactory::createGeometry(wkbGeometryCollection);
OGRFeature *ogrFeature; OGRFeature *ogrFeature;
...@@ -900,16 +897,7 @@ unsigned int OGRIOHelper<TVectorData> ...@@ -900,16 +897,7 @@ unsigned int OGRIOHelper<TVectorData>
return m_Kept; return m_Kept;
} }
/*
template<class TLabelObject, class TPolygon>
inline typename OGRIOHelper<TLabelObject,TPolygon>
::PolygonPointerType
OGRIOHelper<TLabelObject,TPolygon>
::operator()(const LabelObjectType * labelObject)
{
}
*/
} // end namespace otb } // end namespace otb
......
...@@ -250,7 +250,7 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char * ...@@ -250,7 +250,7 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char *
OGRSpatialReference * oSRS = NULL; OGRSpatialReference * oSRS = NULL;
if (projectionInformationAvailable) if (projectionInformationAvailable)
{ {
oSRS = new OGRSpatialReference(projectionRefWkt.c_str()); oSRS = static_cast<OGRSpatialReference *>(OSRNewSpatialReference(projectionRefWkt.c_str()));
} }
// Retrieving root node // Retrieving root node
...@@ -279,7 +279,7 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char * ...@@ -279,7 +279,7 @@ void OGRVectorDataIO<TData>::Write(const VectorDataConstPointerType data, char *
if (oSRS != NULL) if (oSRS != NULL)
{ {
delete oSRS; OSRDestroySpatialReference(oSRS);
} }
chrono.Stop(); chrono.Stop();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment