Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix leak when a transform error occurs while transforming linestrings
  • Loading branch information
nyalldawson committed Mar 12, 2018
1 parent 0d99d31 commit 4af5ff5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/core/geometry/qgslinestring.cpp
Expand Up @@ -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();
}

Expand Down

0 comments on commit 4af5ff5

Please sign in to comment.