ODBC: Fix a memory leak when open() fails.

When connection or login fails, the ODBC SQL driver was leaking memory.
This bug has been present since Qt 4.8 and up.

Task-number: QTBUG-51334
Change-Id: Ie17f3d575a08d47e047a65d1b30af9ce0789b2d0
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
HyungDon Lee 2016-02-24 20:57:14 +09:00 committed by Liang Qi
parent 8135e52cb4
commit bfdbfeb012

View File

@ -1879,11 +1879,14 @@ bool QODBCDriver::open(const QString & db,
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
qSqlWarning(QLatin1String("QODBCDriver::open: Unable to allocate connection"), d);
setOpenError(true);
cleanup();
return false;
}
if (!d->setConnectionOptions(connOpts))
if (!d->setConnectionOptions(connOpts)) {
cleanup();
return false;
}
// Create the connection string
QString connQStr;
@ -1916,6 +1919,7 @@ bool QODBCDriver::open(const QString & db,
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d));
setOpenError(true);
cleanup();
return false;
}
@ -1923,6 +1927,7 @@ bool QODBCDriver::open(const QString & db,
setLastError(qMakeError(tr("Unable to connect - Driver doesn't support all "
"functionality required"), QSqlError::ConnectionError, d));
setOpenError(true);
cleanup();
return false;
}