Commit e2431b61 authored by Christian Ehrlicher's avatar Christian Ehrlicher
Browse files

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
5f66486c

.

Fixes: QTBUG-43889
Change-Id: Ib466a76d014e32c055d203bda15b075ad3dff3d9
Reviewed-by: default avatarAndy Shaw <andy.shaw@qt.io>
Reviewed-by: default avatarJesus Fernandez <jsfdez@gmail.com>
Showing with 7 additions and 5 deletions
......@@ -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();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment