From 3b01247df945ca4f71a23683096d761b2bc65da9 Mon Sep 17 00:00:00 2001 From: Mattias Andersson Date: Thu, 13 Feb 2014 10:41:24 +0100 Subject: [PATCH] Iterate over a copy of the parents container since we are removing elements from the original. --- src/library/librarymodel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/library/librarymodel.cpp b/src/library/librarymodel.cpp index 1e1a9ece8..3e048da67 100644 --- a/src/library/librarymodel.cpp +++ b/src/library/librarymodel.cpp @@ -380,7 +380,11 @@ void LibraryModel::SongsDeleted(const SongList& songs) { // Now delete empty parents QSet divider_keys; while (!parents.isEmpty()) { - for (LibraryItem* node : parents) { + // Since we are going to remove elements from the container, we + // need a copy to iterate over. If we iterate over the original, + // the behavior will be undefined. + QSet parents_copy = parents; + for (LibraryItem* node : parents_copy) { parents.remove(node); if (node->children.count() != 0) continue;