mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 11:04:25 -04:00
Fix object leaks in database code
Qt's database and query model requires that both the queries and the database objects are out of scope before a database connection can safely be removed. Solution: Properly encapsulate databases and queries in "{ }" and use a string to cache the connection name for out-of-scope removal.
This commit is contained in:
@ -552,17 +552,20 @@ void PropertiesDialog::setComics(QList<ComicDB> comics)
|
||||
|
||||
void PropertiesDialog::updateComics()
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
db.open();
|
||||
db.transaction();
|
||||
QList<ComicDB>::iterator itr;
|
||||
for (itr = comics.begin(); itr != comics.end(); itr++) {
|
||||
if (itr->info.edited)
|
||||
DBHelper::update(&(itr->info), db);
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
db.open();
|
||||
db.transaction();
|
||||
QList<ComicDB>::iterator itr;
|
||||
for (itr = comics.begin(); itr != comics.end(); itr++) {
|
||||
if (itr->info.edited)
|
||||
DBHelper::update(&(itr->info), db);
|
||||
}
|
||||
db.commit();
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
db.commit();
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase(databasePath);
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
}
|
||||
|
||||
void PropertiesDialog::setMultipleCover()
|
||||
|
Reference in New Issue
Block a user