diff options
author | Honglei Zhang <honglei.zhang@nokia.com> | 2011-11-29 13:00:16 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-30 13:53:24 +0100 |
commit | d34170aff2707b223b0e22e61efa7a26505f9c6e (patch) | |
tree | c35525d009a738aaf416f3a9b507baa7d481b347 /src | |
parent | 5fb239e8a3117341fa1b0fe4749dbe14e51c2028 (diff) |
Fix sqlite driver memory eating due to close failure
If an ongoing query is not finalized before close function is
called, sqlite driver still tries to close the connection to
sqlite. In this case, sqlite reports an error to sqlite driver
which is not reported to the client. The failure in close causes
connection to sqlite unclosed and memory is not freed. This
fix tries to finalize all queries before close function is called.
The close function should succeed.
Task-number: QTBUG-16967
Change-Id: I2f10a2a9017446a9d44b693b00464a89625e3602
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 8294a55633..38e4a63d57 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -104,6 +104,7 @@ class QSQLiteDriverPrivate public: inline QSQLiteDriverPrivate() : access(0) {} sqlite3 *access; + QList <QSQLiteResult *> results; }; @@ -286,10 +287,12 @@ QSQLiteResult::QSQLiteResult(const QSQLiteDriver* db) { d = new QSQLiteResultPrivate(this); d->access = db->d->access; + db->d->results.append(this); } QSQLiteResult::~QSQLiteResult() { + qobject_cast<const QSQLiteDriver *>(driver())->d->results.removeOne(this); d->cleanup(); delete d; } @@ -553,6 +556,10 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c void QSQLiteDriver::close() { if (isOpen()) { + foreach (QSQLiteResult *result, d->results) { + result->d->finalize(); + } + if (sqlite3_close(d->access) != SQLITE_OK) setLastError(qMakeError(d->access, tr("Error closing database"), QSqlError::ConnectionError)); |