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>bb10
parent
268f41ec70
commit
dedd4a7a7c
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue