Fix crashes due to invalid iterator use

Although the iterators are constant we are indirectly changing them.
Introduced by commit ac42ccb5e4.
Closes #8633
This commit is contained in:
Luís Pereira 2018-03-26 20:21:53 +01:00 committed by sledgehammer999
parent aa122b062e
commit 758c70283f
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2

View file

@ -35,6 +35,7 @@
#include <QMessageBox>
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "categoryfiltermodel.h"
#include "categoryfilterproxymodel.h"
#include "guiiconprovider.h"
@ -232,8 +233,7 @@ void CategoryFilterWidget::removeCategory()
void CategoryFilterWidget::removeUnusedCategories()
{
auto session = BitTorrent::Session::instance();
for (auto i = session->categories().cbegin(); i != session->categories().cend(); ++i) {
const QString &category = i.key();
for (const QString &category : copyAsConst(session->categories().keys())) {
if (model()->data(static_cast<CategoryFilterProxyModel *>(model())->index(category), Qt::UserRole) == 0)
session->removeCategory(category);
}