summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2014-08-01 14:42:30 (GMT)
committerSwift Review <review@swift.im>2014-08-10 10:58:32 (GMT)
commit5e9e715e49a5ddb6ce9c76ec61e7ecfd6eacdb58 (patch)
treec51e752f938c7fc564fe3b84ce12bc374087e918 /Swift/QtUI/ChatList
parentcdc8e88963e2f12cf0a6398a4dd6bb787b456b46 (diff)
downloadswift-5e9e715e49a5ddb6ce9c76ec61e7ecfd6eacdb58.zip
swift-5e9e715e49a5ddb6ce9c76ec61e7ecfd6eacdb58.tar.bz2
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
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h14
1 files changed, 12 insertions, 2 deletions
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();