Skip to content

Commit

Permalink
qgsquadrilateral: Fix memory leak in area and polygon calls
Browse files Browse the repository at this point in the history
The toPolygon() call releases the unique_ptr, the `QgsPolygon` object
needs to be deleted. This achieved by using a `std::unique_ptr` which
automatically frees the polygon at the end of the function.
  • Loading branch information
ptitjano authored and troopa81 committed Apr 13, 2023
1 parent d73264b commit e5c2f56
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/geometry/qgsquadrilateral.cpp
Expand Up @@ -435,10 +435,12 @@ QString QgsQuadrilateral::toString( int pointPrecision ) const

double QgsQuadrilateral::area() const
{
return toPolygon()->area();
std::unique_ptr<QgsPolygon> polygon( toPolygon() );
return polygon->area();
}

double QgsQuadrilateral::perimeter() const
{
return toPolygon()->perimeter();
std::unique_ptr<QgsPolygon> polygon( toPolygon() );
return polygon->perimeter();
}

0 comments on commit e5c2f56

Please sign in to comment.