Skip to content
Permalink
Browse files

[Spatialite provider] Properly destroy QgsSpatiaLiteConnPool singleto…

…n at provider unloading. Should fix frequent crash in PyQgsServerWMS on Travis (fixes #17447)
  • Loading branch information
rouault committed Nov 15, 2017
1 parent 7fa11c8 commit 581d0d30ca89a213b1ba1a56a3fe2af5c896eacd
@@ -13,11 +13,30 @@
* *
***************************************************************************/

#include <QMutex>
#include <QMutexLocker>

#include "qgsspatialiteconnpool.h"

QgsSpatiaLiteConnPool QgsSpatiaLiteConnPool::sInstance;
QgsSpatiaLiteConnPool *QgsSpatiaLiteConnPool::sInstance = nullptr;

QgsSpatiaLiteConnPool *QgsSpatiaLiteConnPool::instance()
{
return &sInstance;
if ( ! sInstance )
{
static QMutex sMutex;
QMutexLocker locker( &sMutex );
if ( ! sInstance )
{
sInstance = new QgsSpatiaLiteConnPool();
}
}
return sInstance;
}

// static public
void QgsSpatiaLiteConnPool::cleanupInstance()
{
delete sInstance;
sInstance = nullptr;
}
@@ -68,9 +68,19 @@ class QgsSpatiaLiteConnPoolGroup : public QObject, public QgsConnectionPoolGroup
//! SpatiaLite connection pool - singleton
class QgsSpatiaLiteConnPool : public QgsConnectionPool<QgsSqliteHandle *, QgsSpatiaLiteConnPoolGroup>
{
static QgsSpatiaLiteConnPool sInstance;
static QgsSpatiaLiteConnPool *sInstance;
public:
static QgsSpatiaLiteConnPool *instance();

// Singleton cleanup
//
// Make sure nobody is using the instance before calling
// this function.
//
// WARNING: concurrent call from multiple threads may result
// in double-free of the instance.
//
static void cleanupInstance();
};


@@ -5900,6 +5900,7 @@ QGISEXTERN QString getStyleById( const QString &uri, QString styleId, QString &e

QGISEXTERN void cleanupProvider()
{
QgsSpatiaLiteConnPool::cleanupInstance();
QgsSqliteHandle::closeAll();
}

1 comment on commit 581d0d3

@pblottiere

This comment has been minimized.

Copy link
Member

@pblottiere pblottiere commented on 581d0d3 Nov 16, 2017

Thank you @rouault! WMS tests seem to be stabilized now 🎉

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