From 0543ed0f150d1f59542d0032b8b8efafdecc24a1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 23 Jun 2010 17:58:33 +0000 Subject: [PATCH] a work around for the fact that groups and items are in the same collection, which can cause issues on destruction BUG:242112 svn path=/trunk/KDE/kdelibs/; revision=1141872 --- extenders/extender.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/extenders/extender.cpp b/extenders/extender.cpp index 41faee118..500dda44a 100644 --- a/extenders/extender.cpp +++ b/extenders/extender.cpp @@ -110,14 +110,30 @@ Extender::Extender(Applet *applet) Extender::~Extender() { d->destroying = true; - QMutableListIterator it(d->attachedExtenderItems); - while (it.hasNext()) { - ExtenderItem *item = it.next(); - item->disconnect(this); - delete item; + + // when deleting items that are connected to us, it can happen that + // other items which are in groups may get deleted as well. so we first + // build a new list of guarded pointers, and then use that list. that + // way when items are deleted behind our back, we are still safe. + // FIXME: having groups and items in the same collection is probably a mistake, + // so would be a good candidate for a refactoring exercise + QList > guardedItems; + + foreach (ExtenderItem *item, d->attachedExtenderItems) { + guardedItems << QWeakPointer(item); } + d->attachedExtenderItems.clear(); + foreach (const QWeakPointer &guardedItem, guardedItems) { + ExtenderItem *item = guardedItem.data(); + if (item) { + item->disconnect(this); + delete item; + } + } + + delete d; }