From: APTX Date: Mon, 15 Apr 2013 19:25:03 +0000 (+0200) Subject: Fix possible crash in Database::exec(). X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=7e3a1cedf783b908e0442f2a2e4091b2fc1974ff;p=localmylist.git Fix possible crash in Database::exec(). Disconnecting clears all prepared statements so a query passed to exec might would invalid. --- diff --git a/localmylist/database.cpp b/localmylist/database.cpp index aba3988..b448a25 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -1701,13 +1701,12 @@ bool Database::exec(QSqlQuery &query) { Q_ASSERT_X(d->thread == QThread::currentThread(), "threads", "DB used from different thread"); - if (!d->db.isOpen()) + if (!isConnected()) { disconnect(); - if (!connect()) - return false; + connect(); - return retryExec(query, true); + return false; } if (!query.exec()) @@ -1719,7 +1718,7 @@ bool Database::exec(const QString &sql) { Q_ASSERT_X(d->thread == QThread::currentThread(), "threads", "DB used from different thread"); - if (!d->db.isOpen()) + if (!isConnected()) { disconnect(); if (!connect())