Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix leaks
  • Loading branch information
nyalldawson committed Jun 5, 2016
1 parent fab16ec commit f70be07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -354,11 +354,11 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
double min = lineEditValue( mMinLineEdit );
double max = lineEditValue( mMaxLineEdit );

QgsVectorColorRampV2* colorRamp = mColorRampComboBox->currentColorRamp();
QScopedPointer< QgsVectorColorRampV2 > colorRamp( mColorRampComboBox->currentColorRamp() );

if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Continuous )
{
if ( colorRamp )
if ( colorRamp.data() )
{
numberOfEntries = colorRamp->count();
entryValues.reserve( numberOfEntries );
Expand All @@ -367,7 +367,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
double intervalDiff = max - min;

// remove last class when ColorRamp is gradient and discrete, as they are implemented with an extra stop
QgsVectorGradientColorRampV2* colorGradientRamp = dynamic_cast<QgsVectorGradientColorRampV2*>( colorRamp );
QgsVectorGradientColorRampV2* colorGradientRamp = dynamic_cast<QgsVectorGradientColorRampV2*>( colorRamp.data() );
if ( colorGradientRamp != NULL && colorGradientRamp->isDiscrete() )
{
numberOfEntries--;
Expand Down Expand Up @@ -405,7 +405,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
else // for other classification modes interpolate colors linearly
{
numberOfEntries = mNumberOfEntriesSpinBox->value();
if ( numberOfEntries < 2 ) return; // < 2 classes is not useful, shouldn't happen, but if it happens save it from crashing
if ( numberOfEntries < 2 )
return; // < 2 classes is not useful, shouldn't happen, but if it happens save it from crashing

if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Quantile )
{ // Quantile
Expand Down Expand Up @@ -470,7 +471,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
}
}

if ( ! colorRamp )
if ( !colorRamp.data() )
{
//hard code color range from blue -> red (previous default)
int colorDiff = 0;
Expand Down
35 changes: 18 additions & 17 deletions src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -104,12 +104,12 @@ static QgsPointV2* parsePoint( const QVariantList& coordList, QgsWKBTypes::Type
{
int nCoords = coordList.size();
if ( nCoords < 2 )
return 0;
return nullptr;
bool xok = false, yok = false;
double x = coordList[0].toDouble( &xok );
double y = coordList[1].toDouble( &yok );
if ( !xok || !yok )
return 0;
return nullptr;
double z = nCoords >= 3 ? coordList[2].toDouble() : 0;
double m = nCoords >= 4 ? coordList[3].toDouble() : 0;
return new QgsPointV2( pointType, x, y, z, m );
Expand All @@ -119,15 +119,16 @@ static QgsCircularStringV2* parseCircularString( const QVariantMap& curveData, Q
{
QVariantList coordsList = curveData["c"].toList();
if ( coordsList.isEmpty() )
return 0;
return nullptr;
QList<QgsPointV2> points;
points.append( startPoint );
foreach ( const QVariant& coordData, coordsList )
{
QgsPointV2* point = parsePoint( coordData.toList(), pointType );
if ( points.last() == 0 )
{
return 0;
delete point;
return nullptr;
}
points.append( *point );
delete point;
Expand All @@ -151,7 +152,7 @@ static QgsCompoundCurveV2* parseCompoundCurve( const QVariantList& curvesList, Q
if ( !point )
{
delete compoundCurve;
return 0;
return nullptr;
}
lineString->addVertex( *point );
delete point;
Expand All @@ -163,7 +164,7 @@ static QgsCompoundCurveV2* parseCompoundCurve( const QVariantList& curvesList, Q
if ( !circularString )
{
delete compoundCurve;
return 0;
return nullptr;
}

// If the previous curve had less than two points, remove it
Expand All @@ -188,7 +189,7 @@ static QgsAbstractGeometryV2* parseEsriGeometryPoint( const QVariantMap& geometr
double x = geometryData["x"].toDouble( &xok );
double y = geometryData["y"].toDouble( &yok );
if ( !xok || !yok )
return 0;
return nullptr;
double z = geometryData["z"].toDouble();
double m = geometryData["m"].toDouble();
return new QgsPointV2( pointType, x, y, z, m );
Expand All @@ -199,7 +200,7 @@ static QgsAbstractGeometryV2* parseEsriGeometryMultiPoint( const QVariantMap& ge
// {"points" : [[ <x1>, <y1>, <z1>, <m1> ] , [ <x2>, <y2>, <z2>, <m2> ], ... ]}
QVariantList coordsList = geometryData["points"].toList();
if ( coordsList.isEmpty() )
return 0;
return nullptr;

QgsMultiPointV2* multiPoint = new QgsMultiPointV2();
foreach ( QVariant coordData, coordsList )
Expand All @@ -209,7 +210,7 @@ static QgsAbstractGeometryV2* parseEsriGeometryMultiPoint( const QVariantMap& ge
if ( !p )
{
delete multiPoint;
return 0;
return nullptr;
}
multiPoint->addGeometry( p );
}
Expand All @@ -225,15 +226,15 @@ static QgsAbstractGeometryV2* parseEsriGeometryPolyline( const QVariantMap& geom
else if ( geometryData["curvePaths"].isValid() )
pathsList = geometryData["curvePaths"].toList();
if ( pathsList.isEmpty() )
return 0;
return nullptr;
QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
foreach ( const QVariant& pathData, pathsList )
{
QgsCompoundCurveV2* curve = parseCompoundCurve( pathData.toList(), pointType );
if ( !curve )
{
delete multiCurve;
return 0;
return nullptr;
}
multiCurve->addGeometry( curve );
}
Expand All @@ -249,13 +250,13 @@ static QgsAbstractGeometryV2* parseEsriGeometryPolygon( const QVariantMap& geome
else if ( geometryData["ringPaths"].isValid() )
ringsList = geometryData["ringPaths"].toList();
if ( ringsList.isEmpty() )
return 0;
return nullptr;
QgsCurvePolygonV2* polygon = new QgsCurvePolygonV2();
QgsCompoundCurveV2* ext = parseCompoundCurve( ringsList.front().toList(), pointType );
if ( !ext )
{
delete polygon;
return 0;
return nullptr;
}
polygon->setExteriorRing( ext );
for ( int i = 1, n = ringsList.size(); i < n; ++i )
Expand All @@ -264,7 +265,7 @@ static QgsAbstractGeometryV2* parseEsriGeometryPolygon( const QVariantMap& geome
if ( !curve )
{
delete polygon;
return 0;
return nullptr;
}
polygon->addInteriorRing( curve );
}
Expand All @@ -280,7 +281,7 @@ static QgsAbstractGeometryV2* parseEsriEnvelope( const QVariantMap& geometryData
double xmax = geometryData["xmax"].toDouble( &xmaxOk );
double ymax = geometryData["ymax"].toDouble( &ymaxOk );
if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk )
return 0;
return nullptr;
QgsLineStringV2* ext = new QgsLineStringV2();
ext->addVertex( QgsPointV2( xmin, ymin ) );
ext->addVertex( QgsPointV2( xmax, ymin ) );
Expand All @@ -302,7 +303,7 @@ QgsAbstractGeometryV2* QgsArcGisRestUtils::parseEsriGeoJSON( const QVariantMap&

// http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Geometry_Objects/02r3000000n1000000/
if ( esriGeometryType == "esriGeometryNull" )
return 0;
return nullptr;
else if ( esriGeometryType == "esriGeometryPoint" )
return parseEsriGeometryPoint( geometryData, pointType );
else if ( esriGeometryType == "esriGeometryMultipoint" )
Expand All @@ -328,7 +329,7 @@ QgsAbstractGeometryV2* QgsArcGisRestUtils::parseEsriGeoJSON( const QVariantMap&
// esriGeometrySphere
// esriGeometryTriangles
// esriGeometryBag
return 0;
return nullptr;
}

QgsCoordinateReferenceSystem QgsArcGisRestUtils::parseSpatialReference( const QVariantMap &spatialReferenceMap )
Expand Down

0 comments on commit f70be07

Please sign in to comment.