Skip to content

Commit

Permalink
Fix potential crash in marker symbol layer
Browse files Browse the repository at this point in the history
(the expression context scope wasn't being deleted in all return
paths, resulting in crashes when rendering was complete and
everything was being cleaned up)

And some other code safer against this same risk

(cherry picked from commit 2835ed6)
  • Loading branch information
nyalldawson committed Aug 6, 2019
1 parent d015ab8 commit c640f07
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/core/qgsvectorlayerrenderer.cpp
Expand Up @@ -350,7 +350,7 @@ void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
}

QgsExpressionContextScope *symbolScope = QgsExpressionContextUtils::updateSymbolScope( nullptr, new QgsExpressionContextScope() );
mContext.expressionContext().appendScope( symbolScope );
std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = qgis::make_unique< QgsExpressionContextScopePopper >( mContext.expressionContext(), symbolScope );

// 1. fetch features
QgsFeature fet;
Expand All @@ -360,7 +360,6 @@ void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
{
qDebug( "rendering stop!" );
stopRenderer( selRenderer );
delete mContext.expressionContext().popScope();
return;
}

Expand Down Expand Up @@ -407,7 +406,7 @@ void QgsVectorLayerRenderer::drawRendererLevels( QgsFeatureIterator &fit )
}
}

delete mContext.expressionContext().popScope();
scopePopper.reset();

if ( features.empty() )
{
Expand Down
12 changes: 3 additions & 9 deletions src/core/symbology/qgslinesymbollayer.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsgeometrysimplifier.h"
#include "qgsunittypes.h"
#include "qgsproperty.h"
#include "qgsexpressioncontextutils.h"

#include <QPainter>
#include <QDomDocument>
Expand Down Expand Up @@ -1080,7 +1081,7 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p
double interval = mInterval;

QgsExpressionContextScope *scope = new QgsExpressionContextScope();
context.renderContext().expressionContext().appendScope( scope );
QgsExpressionContextScopePopper scopePopper( context.renderContext().expressionContext(), scope );

if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyInterval ) )
{
Expand Down Expand Up @@ -1211,8 +1212,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineInterval( const QPolygonF &p
}

}

delete context.renderContext().expressionContext().popScope();
}

static double _averageAngle( QPointF prevPt, QPointF pt, QPointF nextPt )
Expand All @@ -1237,7 +1236,7 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
bool isRing = false;

QgsExpressionContextScope *scope = new QgsExpressionContextScope();
context.renderContext().expressionContext().appendScope( scope );
QgsExpressionContextScopePopper scopePopper( context.renderContext().expressionContext(), scope );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size(), true ) );

double offsetAlongLine = mOffsetAlongLine;
Expand Down Expand Up @@ -1293,7 +1292,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
}
}

delete context.renderContext().expressionContext().popScope();
return;
}

Expand Down Expand Up @@ -1326,7 +1324,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
case CentralPoint:
case CurvePoint:
{
delete context.renderContext().expressionContext().popScope();
return;
}
}
Expand All @@ -1339,7 +1336,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi
// restore original rotation
setSymbolAngle( origAngle );

delete context.renderContext().expressionContext().popScope();
return;
}

Expand All @@ -1364,8 +1360,6 @@ void QgsTemplatedLineSymbolLayerBase::renderPolylineVertex( const QPolygonF &poi

// restore original rotation
setSymbolAngle( origAngle );

delete context.renderContext().expressionContext().popScope();
}

double QgsTemplatedLineSymbolLayerBase::markerAngle( const QPolygonF &points, bool isRing, int vertex )
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgspointdistancerenderer.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsspatialindex.h"
#include "qgsmultipoint.h"
#include "qgslogger.h"
#include "qgsexpressioncontextutils.h"

#include <QDomElement>
#include <QPainter>
Expand Down Expand Up @@ -150,9 +151,8 @@ void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup &group, QgsRender
QPointF pt = centroid.asQPointF();
context.mapToPixel().transformInPlace( pt.rx(), pt.ry() );

context.expressionContext().appendScope( createGroupScope( group ) );
QgsExpressionContextScopePopper scopePopper( context.expressionContext(), createGroupScope( group ) );
drawGroup( pt, context, group );
delete context.expressionContext().popScope();
}

void QgsPointDistanceRenderer::setEmbeddedRenderer( QgsFeatureRenderer *r )
Expand Down

0 comments on commit c640f07

Please sign in to comment.