diff options
author | Honglei Zhang <honglei.zhang@nokia.com> | 2012-03-12 16:52:25 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-13 21:11:55 +0100 |
commit | dedd4a7a7ca9be18ed9fc958ea4da48c2f1fd82f (patch) | |
tree | 92101a5e6abce2c00246529942edc54b937d2c52 /src/sql/drivers | |
parent | 268f41ec70fd70d4aa44a5043d1a4e678df4c5b5 (diff) |
Fix memory leak when sqlite3_open_v2 fails
According to SQLite documentation, a database connection handle
is usually returned, even if an error occurs. This behavior has
caused Qt to leak memory when opening a database is failed. Now,
even if sqlite3_open_v2() does not return SQLITE_OK, Qt tries to
release SQLite database handle by calling sqlite3_close().
Task-number: QTBUG-15773
Change-Id: I6538e2897216828a9cfb95b7d4a5cec437aa6c28
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src/sql/drivers')
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index b2a55252ac..deb29f8059 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -577,6 +577,11 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c setOpenError(false); return true; } else { + if (d->access) { + sqlite3_close(d->access); + d->access = 0; + } + setLastError(qMakeError(d->access, tr("Error opening database"), QSqlError::ConnectionError)); setOpenError(true); |