Skip to content

Commit 9a161ac

Browse files
committed
Fix crash on exit: delete postgres connection pool before QApplication
1 parent 601e430 commit 9a161ac

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/providers/postgres/qgspostgresconnpool.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@
1616
#include "qgspostgresconnpool.h"
1717
#include "qgspostgresconn.h"
1818

19-
QgsPostgresConnPool QgsPostgresConnPool::sInstance;
19+
QgsPostgresConnPool* QgsPostgresConnPool::sInstance = nullptr;
2020

2121
QgsPostgresConnPool* QgsPostgresConnPool::instance()
2222
{
23-
return &sInstance;
23+
if ( !sInstance )
24+
sInstance = new QgsPostgresConnPool();
25+
return sInstance;
26+
}
27+
28+
void QgsPostgresConnPool::cleanupInstance()
29+
{
30+
delete sInstance;
31+
sInstance = nullptr;
2432
}
2533

2634
QgsPostgresConnPool::QgsPostgresConnPool() : QgsConnectionPool<QgsPostgresConn*, QgsPostgresConnPoolGroup>()

src/providers/postgres/qgspostgresconnpool.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ class QgsPostgresConnPool : public QgsConnectionPool<QgsPostgresConn*, QgsPostgr
7070
public:
7171
static QgsPostgresConnPool* instance();
7272

73+
static void cleanupInstance();
74+
7375
protected:
7476
Q_DISABLE_COPY( QgsPostgresConnPool )
7577

7678
private:
7779
QgsPostgresConnPool();
7880
~QgsPostgresConnPool();
7981

80-
static QgsPostgresConnPool sInstance;
82+
static QgsPostgresConnPool* sInstance;
8183
};
8284

8385

src/providers/postgres/qgspostgresprovider.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4130,6 +4130,10 @@ QGISEXTERN QgsTransaction* createTransaction( const QString& connString )
41304130
return new QgsPostgresTransaction( connString );
41314131
}
41324132

4133+
QGISEXTERN void cleanupProvider()
4134+
{
4135+
QgsPostgresConnPool::cleanupInstance();
4136+
}
41334137

41344138
// ----------
41354139

0 commit comments

Comments
 (0)