Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.8.6, 5.4.1, 5.5.1
-
None
-
bfdbfeb01233a76ea36f53c4f4be9014db5d8d86
Description
ODBC driver memory leak when QDatabase call open mthod failed.
sample code:
initialize method
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3", QString("DB")); db.setDatabaseName(QString("DRIVER={SQL Server};SERVER=127.0.0.1,1433;DATABASE=TEST;UID=TEST;PWD=TEST;"));
process thread
QSqlDatabase db = QSqlDatabase::database(QString("DB"), false); if(!db.isOpen()) { if(!db.open()) { ... } }
hEnv, hDbc resource is not release on connect or login fails.
This problem solution, when return false, before call cleanup method.
or... Temporary solution (without pre initiallize)
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3", QString("DB")); db.setDatabaseName(QString("DRIVER={SQL Server};SERVER=127.0.0.1,1433;DATABASE=TEST;UID=TEST;PWD=TEST;")); if(db.open()) { .... } db = QSqlDatabase(); QSqlDatabase::removeDatabase("DB");
This bug has been present since Qt 4.8 and up.
Attached file is diff of Qt 5.4.1 version qsql_odbc.cpp