summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Möller <m_moeller@live.de>2020-12-09 21:39:20 +0100
committerTarja Sundqvist <tarja.sundqvist@qt.io>2021-02-08 14:37:45 +0200
commitf9bcef1b17e822cfbceb9c0b6dac23b896195738 (patch)
treeacd237c738ba789b1a5f5ce228db78043046c657
parent6a64b8ed56d70d76cc154e66f03824b3c3a2a786 (diff)
fix potential mem leak on connection lost
The PostgreSQL driver can change it's connection status after the first established connection. In this case, the function "isOpen()" returns false and the "close()" function would not free all resources. With this fix, the "close()" function always frees any allocated resource independent of the connection status. Fixes: QTBUG-88984 Change-Id: I7c9add6a183bf46a8573952ab39f8cb1f728c00c Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 6e9125608f2c07c6c5f41a7a42ea097d1333e1e3)
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index d35dc9554a..cd27d2c015 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -1198,8 +1198,7 @@ bool QPSQLDriver::open(const QString &db,
const QString &connOpts)
{
Q_D(QPSQLDriver);
- if (isOpen())
- close();
+ close();
QString connectString;
if (!host.isEmpty())
connectString.append(QLatin1String("host=")).append(qQuote(host));
@@ -1242,21 +1241,19 @@ bool QPSQLDriver::open(const QString &db,
void QPSQLDriver::close()
{
Q_D(QPSQLDriver);
- if (isOpen()) {
- d->seid.clear();
- if (d->sn) {
- disconnect(d->sn, SIGNAL(activated(QSocketDescriptor)), this, SLOT(_q_handleNotification()));
- delete d->sn;
- d->sn = nullptr;
- }
-
- if (d->connection)
- PQfinish(d->connection);
- d->connection = nullptr;
- setOpen(false);
- setOpenError(false);
+ d->seid.clear();
+ if (d->sn) {
+ disconnect(d->sn, SIGNAL(activated(QSocketDescriptor)), this, SLOT(_q_handleNotification()));
+ delete d->sn;
+ d->sn = nullptr;
}
+
+ if (d->connection)
+ PQfinish(d->connection);
+ d->connection = nullptr;
+ setOpen(false);
+ setOpenError(false);
}
QSqlResult *QPSQLDriver::createResult() const