From 5f66486cc254e1483f776d3058f96db493fd26e5 Mon Sep 17 00:00:00 2001 From: Marcel Krems Date: Wed, 21 Feb 2018 19:19:36 +0100 Subject: [PATCH] Fix crash when deleting a QSqlQueryModel after closing the database Task-number: QTBUG-66553 Change-Id: Ib5c04ebe5ac2b7581613e0044804072eb0980b2e Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index b4eb69e6cf..5e0f7626b4 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -462,8 +462,10 @@ void QPSQLResult::cleanup() d->result = nullptr; while (!d->nextResultSets.isEmpty()) PQclear(d->nextResultSets.takeFirst()); - if (d->stmtId != InvalidStatementId) - d->drv_d_func()->finishQuery(d->stmtId); + if (d->stmtId != InvalidStatementId) { + if (d->drv_d_func()) + d->drv_d_func()->finishQuery(d->stmtId); + } d->stmtId = InvalidStatementId; setAt(QSql::BeforeFirstRow); d->currentSize = -1;