Skip to content
Permalink
Browse files

Fix leak when a transform error occurs while transforming linestrings

  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 0d99d31 commit 4af5ff500a8addf8df5770ec49785ec30c86d0f7
Showing with 11 additions and 12 deletions.
  1. +11 −12 src/core/geometry/qgslinestring.cpp
@@ -786,24 +786,23 @@ int QgsLineString::dimension() const

void QgsLineString::transform( const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d, bool transformZ )
{
double *zArray = mZ.data();

double *zArray = nullptr;
bool hasZ = is3D();
int nPoints = numPoints();
bool useDummyZ = !hasZ || !transformZ;
if ( useDummyZ )

// it's possible that transformCoords will throw an exception - so we need to use
// a smart pointer for the dummy z values in order to ensure that they always get cleaned up
std::unique_ptr< double[] > dummyZ;
if ( !hasZ || !transformZ )
{
zArray = new double[nPoints];
for ( int i = 0; i < nPoints; ++i )
{
zArray[i] = 0;
}
dummyZ.reset( new double[nPoints]() );
zArray = dummyZ.get();
}
ct.transformCoords( nPoints, mX.data(), mY.data(), zArray, d );
if ( useDummyZ )
else
{
delete[] zArray;
zArray = mZ.data();
}
ct.transformCoords( nPoints, mX.data(), mY.data(), zArray, d );
clearCache();
}

0 comments on commit 4af5ff5

Please sign in to comment.
You can’t perform that action at this time.