Skip to content

Commit

Permalink
Fix Coverity use-after-free (and possible leak)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 28, 2015
1 parent c24192b commit dec4f5c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ int QgsGeometry::addRing( QgsCurveV2* ring )
{
if ( !d || !d->geometry )
{
delete ring;
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ int QgsVectorLayer::addRing( QgsCurveV2* ring )
{
if ( !mEditBuffer || !mDataProvider )
{
delete ring;
return 6;
}

Expand All @@ -1066,7 +1067,8 @@ int QgsVectorLayer::addRing( QgsCurveV2* ring )

if ( !ring->isClosed() )
{
delete ring; return 2;
delete ring;
return 2;
}

QgsVectorLayerEditUtils utils( this );
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsvectorlayereditutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring )
int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring )
{
if ( !L->hasGeometryType() )
{
delete ring;
return 5;
}

int addRingReturnCode = 5; //default: return code for 'ring not inserted'
QgsRectangle bBox = ring->boundingBox();
Expand All @@ -129,7 +132,8 @@ int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring )
QgsFeature f;
while ( fit.nextFeature( f ) )
{
addRingReturnCode = f.geometry()->addRing( ring );
//add ring takes ownership of ring, and deletes it if there's an error
addRingReturnCode = f.geometry()->addRing( static_cast< QgsCurveV2* >( ring->clone() ) );
if ( addRingReturnCode == 0 )
{
L->editBuffer()->changeGeometry( f.id(), f.geometry() );
Expand All @@ -139,6 +143,7 @@ int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring )
}
}

delete ring;
return addRingReturnCode;
}

Expand Down

0 comments on commit dec4f5c

Please sign in to comment.