Skip to content
Browse files
[BUGFIX] QgsMSLayerCache: remove layer from QgsMapLayerRegistry befor…
…e delete it

In QGIS Server, layers can be added to QgsMapLayerRegistry and delete by QgsMSLayerCache. This means that QgsMapLayerRegistry can have reference to deleted pointers.
  • Loading branch information
rldhont committed Jun 28, 2016
1 parent 7dcb9cc commit d3eb164582af7253ef94304d25e4555f1acb1e07
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/server/qgsmslayercache.cpp
@@ -17,6 +17,8 @@

#include "qgsmslayercache.h"
#include "qgsmessagelog.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include <QFile>
@@ -187,6 +189,10 @@ void QgsMSLayerCache::removeLeastUsedEntry()

void QgsMSLayerCache::freeEntryRessources( QgsMSLayerCacheEntry& entry )
// remove layer from QgsMapLayerRegistry before delete it
if ( QgsMapLayerRegistry::instance()->mapLayer( entry.layerPointer->id() ) )
QgsMapLayerRegistry::instance()->removeMapLayer( entry.layerPointer->id() );

delete entry.layerPointer;

//remove the temporary files of a layer

2 comments on commit d3eb164


This comment has been minimized.

Copy link

@m-kuhn m-kuhn replied Jun 28, 2016

Another approach would be to connect to QgsMapLayer::destroyed when adding a layer to QgsMapLayerRegistry. That would avoid ever ending up in that situation regardless of the context.
Not sure if there's also a drawback to that.


This comment has been minimized.

Copy link
Contributor Author

@rldhont rldhont replied Jun 29, 2016

I have tested to remove references on QgsMapLayer::destroyed but it doesn't work and segfault QGIS.

Please sign in to comment.