Skip to content
Permalink
Browse files

Safer memory management

  • Loading branch information
nyalldawson committed Nov 27, 2018
1 parent 1a199d0 commit 2a03d2b210a3cb8ad2886d1d40f0e2e696dcfc81
@@ -796,9 +796,9 @@ void QgsAppLayerTreeViewMenuProvider::setSymbolLegendNodeColor( const QColor &co
if ( !originalSymbol )
return;

QgsSymbol *newSymbol = originalSymbol->clone();
std::unique_ptr< QgsSymbol > newSymbol( originalSymbol->clone() );
newSymbol->setColor( color );
node->setSymbol( newSymbol );
node->setSymbol( newSymbol.release() );
if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( layerId ) ) )
{
layer->emitStyleChanged();
@@ -203,12 +203,13 @@ void QgsSymbolLegendNode::setSymbol( QgsSymbol *symbol )
if ( !symbol )
return;

std::unique_ptr< QgsSymbol > s( symbol ); // this method takes ownership of symbol
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( !vlayer || !vlayer->renderer() )
return;

mItem.setSymbol( symbol );
vlayer->renderer()->setLegendSymbolItem( mItem.ruleKey(), symbol );
mItem.setSymbol( s.get() ); // doesn't transfer ownership
vlayer->renderer()->setLegendSymbolItem( mItem.ruleKey(), s.release() ); // DOES transfer ownership!

mPixmap = QPixmap();

0 comments on commit 2a03d2b

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