Skip to content

Commit

Permalink
[Bugfix][Server][WFS] Segfault when converting geom to multi
Browse files Browse the repository at this point in the history
Following 55928c0, [Bugfix][Server][WFS] In GML geometry has all to be multi, in which to avoid memory leak, I don't use a pointer but convertToMuli segfaults in this case.

@nyalldawson has mentioned in the PR #8243 to ignore is comment about pointer, what I missed. So the code has segfaulting.

This commit fixed it by using point and delete it.
  • Loading branch information
rldhont committed Oct 25, 2018
1 parent 75a170d commit 81f4bdb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/server/qgswfsserver.cpp
Expand Up @@ -2070,12 +2070,11 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
typeNameElement.setAttribute( "fid", mTypeName + "." + gmlId );
featureElement.appendChild( typeNameElement );

const QgsGeometry* geom = feat->constGeometry();
const QgsGeometry* cGeom = feat->constGeometry();
QgsGeometry *geom = new QgsGeometry( *cGeom );
if ( isMultiGeom && QgsWKBTypes::isSingleType( QGis::fromOldWkbType( geom->wkbType() ) ) )
{
QgsGeometry cloneGeom( *geom );
cloneGeom.convertToMultiType();
geom = &cloneGeom;
geom->convertToMultiType();
}
if ( geom && mWithGeom && mGeometryName != "NONE" )
{
Expand Down Expand Up @@ -2121,6 +2120,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
typeNameElement.appendChild( geomElem );
}
}
delete geom;

//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
Expand Down Expand Up @@ -2160,12 +2160,12 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
typeNameElement.setAttribute( "gml:id", mTypeName + "." + gmlId );
featureElement.appendChild( typeNameElement );

const QgsGeometry* geom = feat->constGeometry();

const QgsGeometry* cGeom = feat->constGeometry();
QgsGeometry *geom = new QgsGeometry( *cGeom );
if ( isMultiGeom && QgsWKBTypes::isSingleType( QGis::fromOldWkbType( geom->wkbType() ) ) )
{
QgsGeometry cloneGeom( *geom );
cloneGeom.convertToMultiType();
geom = &cloneGeom;
geom->convertToMultiType();
}
if ( geom && mWithGeom && mGeometryName != "NONE" )
{
Expand Down Expand Up @@ -2211,6 +2211,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
typeNameElement.appendChild( geomElem );
}
}
delete geom;

//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
Expand Down

0 comments on commit 81f4bdb

Please sign in to comment.