Skip to content

Commit

Permalink
Replace GEOSGeomScopedPtr with unique_ptr with custom deleter
Browse files Browse the repository at this point in the history
And make greater use of it through QgsGeos to avoid potential
memory leaks.
  • Loading branch information
nyalldawson committed Oct 19, 2017
1 parent a406739 commit 6fe89fd
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 346 deletions.
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Expand Up @@ -264,7 +264,7 @@ GEOSGeometry *QgsGeometry::exportToGeos( double precision ) const
return nullptr;
}

return QgsGeos::asGeos( d->geometry.get(), precision );
return QgsGeos::asGeos( d->geometry.get(), precision ).release();
}


Expand Down
5 changes: 2 additions & 3 deletions src/core/geometry/qgsgeometrymakevalid.cpp
Expand Up @@ -905,7 +905,7 @@ std::unique_ptr< QgsAbstractGeometry > _qgis_lwgeom_make_valid( const QgsAbstrac
// otherwise (adding only duplicates of existing points)
GEOSContextHandle_t handle = QgsGeos::getGEOSHandler();

GEOSGeometry *geosgeom = QgsGeos::asGeos( lwgeom_in );
geos::unique_ptr geosgeom = QgsGeos::asGeos( lwgeom_in );
if ( !geosgeom )
{
QgsDebugMsg( "Original geom can't be converted to GEOS - will try cleaning that up first" );
Expand All @@ -931,8 +931,7 @@ std::unique_ptr< QgsAbstractGeometry > _qgis_lwgeom_make_valid( const QgsAbstrac
QgsDebugMsgLevel( "original geom converted to GEOS", 4 );
}

GEOSGeometry *geosout = LWGEOM_GEOS_makeValid( geosgeom, errorMessage );
GEOSGeom_destroy_r( handle, geosgeom );
GEOSGeometry *geosout = LWGEOM_GEOS_makeValid( geosgeom.get(), errorMessage );
if ( !geosout )
return nullptr;

Expand Down

0 comments on commit 6fe89fd

Please sign in to comment.