summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/psql
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-09-15 19:49:32 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-09-16 10:04:18 +0200
commite2431b619da5c53d34df0b46105deb4450ed0c1f (patch)
tree5bedcedb8c6074be001c3e9bb1dab358e0ca6e5c /src/plugins/sqldrivers/psql
parent5f3bbd0cf091d75661e9390696683285368edb2c (diff)
QPSQL: Fix crash when a prepared statement is deleted after the db was removed
When a prepared statement is still alive after the database was removed with QSqlDatabase::removeDatabase(), the cleanup routine is trying to access the driver which is no longer alive which results in a crash. Fix it by checking if the driver is still alive similar to 5f66486cc254e1483f776d3058f96db493fd26e5. Fixes: QTBUG-43889 Change-Id: Ib466a76d014e32c055d203bda15b075ad3dff3d9 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Diffstat (limited to 'src/plugins/sqldrivers/psql')
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index 0bae45382d..28be7bdc38 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t)
void QPSQLResultPrivate::deallocatePreparedStmt()
{
- const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId;
- PGresult *result = drv_d_func()->exec(stmt);
+ if (drv_d_func()) {
+ const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId;
+ PGresult *result = drv_d_func()->exec(stmt);
- if (PQresultStatus(result) != PGRES_COMMAND_OK)
- qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection));
- PQclear(result);
+ if (PQresultStatus(result) != PGRES_COMMAND_OK)
+ qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection));
+ PQclear(result);
+ }
preparedStmtId.clear();
}