From 5e9e715e49a5ddb6ce9c76ec61e7ecfd6eacdb58 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Fri, 1 Aug 2014 15:42:30 +0100
Subject: Address memory leak

I'd rather do this with shared_ptr, as there's an ownership transfer. This just gets it into somewhere we'll remember it

Change-Id: I5f6872bce8070cbcce44de84eff5e9ed83f88fb9

diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
index 17defea..3bb4b8e 100644
--- a/Swift/QtUI/ChatList/ChatListGroupItem.h
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
  * Licensed under the GNU General Public License v3.
  * See Documentation/Licenses/GPLv3.txt for more information.
  */
@@ -8,19 +8,29 @@
 
 #include <QList>
 
+#include <Swiften/Base/foreach.h>
+
 #include "Swift/QtUI/ChatList/ChatListItem.h"
 
 namespace Swift {
 	class ChatListGroupItem : public ChatListItem {
 		public:
 			ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}
+			virtual ~ChatListGroupItem() {clear();}
 			void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}
 			void remove(int index) {items_.removeAt(index);}
 			int rowCount() {return items_.size();}
 			ChatListItem* item(int i) {return items_[i];}
 			int row(ChatListItem* item) {return items_.indexOf(item);}
 			QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();}
-			void clear() {items_.clear();}
+			void clear() {
+				foreach (ChatListItem* item, items_) {
+					delete item;
+				}
+				items_.clear();
+			}
+
+
 		private:
 			static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
 				QString myName = first->data(Qt::DisplayRole).toString().toLower();
-- 
cgit v0.10.2-6-g49f6