From fb55e1e71e3c98aca880c23d97f9e811e2b406a0 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 30 Jun 2020 18:49:57 +0200 Subject: Sql: Fix heap-user-after-free for globally initialized db objects Becaues the database objects were created as globals, there was a possible use-after-free issue when deleting the objects on application exit. Move the initialization of the database objects into static variables inside the test constructor. As a drive-by, also add one missing test to the CMake projects. Fixes: QTBUG-85357 Change-Id: I2c8f2c5daee96bb9d1d21dae37950a2da5ffdf27 Reviewed-by: Joerg Bornemann --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index dae44c8ec0..54bdd52230 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -33,7 +33,7 @@ #include "../qsqldatabase/tst_databases.h" -const QString qtest(qTableName("qtest", __FILE__, QSqlDatabase())); +QString qtest; class tst_QSqlQuery : public QObject { @@ -271,6 +271,8 @@ private: tst_QSqlQuery::tst_QSqlQuery() { + static QSqlDatabase static_qtest_db = QSqlDatabase(); + qtest = qTableName("qtest", __FILE__, static_qtest_db); } tst_QSqlQuery::~tst_QSqlQuery() -- cgit v1.2.3