From 0cfa934c4c0323cc9e8e1431f25a05977e3670a6 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Mon, 13 Jul 2015 15:18:19 +0200 Subject: Fix memory leak in QtUserSearchWindow The delegate was not correctly freed and was leaking across login/logout sessions. Setting the parent of the delegate during initialization, so it will be freed by Qt when the QtUserSearchWindow is freed. Delegated the deallocation to Qt, because it has to be freed after the widget that uses the delegate is freed. Test-Information: The leak was reported by Valgrind. Verified with Valgrind that this commit fixes the leak and is not reported anymore. Change-Id: Ib48d2628577433bce82103b3f14cbd11d733b7ac diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index cff34d8..737196a 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -1,36 +1,38 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Swift/QtUI/UserSearch/QtUserSearchWindow.h" +#include + +#include +#include #include #include -#include #include -#include -#include +#include +#include #include -#include -#include + #include #include #include -#include -#include -#include +#include +#include + #include -#include -#include +#include +#include +#include #include +#include +#include #include -#include -#include - -#include +#include +#include namespace Swift { @@ -53,7 +55,7 @@ QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWin } setWindowTitle(title); - delegate_ = new UserSearchDelegate(); + delegate_ = new UserSearchDelegate(this); setFirstPage(title); setSecondPage(); diff --git a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp index 35793f4..1ac9eb3 100644 --- a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp +++ b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp @@ -1,24 +1,24 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include +#include + +#include +#include #include +#include #include -#include -#include -#include "Swift/QtUI/UserSearch/UserSearchDelegate.h" -//#include "Swift/QtUI/Roster/GroupItemDelegate.h" #include + #include -//#include "Swift/QtUI/MUCSearch/MUCSearchServiceItem.h" namespace Swift { -UserSearchDelegate::UserSearchDelegate() { +UserSearchDelegate::UserSearchDelegate(QObject* parent) : QStyledItemDelegate(parent) { } diff --git a/Swift/QtUI/UserSearch/UserSearchDelegate.h b/Swift/QtUI/UserSearch/UserSearchDelegate.h index 41c20dc..92fa0e8 100644 --- a/Swift/QtUI/UserSearch/UserSearchDelegate.h +++ b/Swift/QtUI/UserSearch/UserSearchDelegate.h @@ -1,22 +1,25 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include #include #include +#include #include namespace Swift { class UserSearchDelegate : public QStyledItemDelegate { + Q_OBJECT + public: - UserSearchDelegate(); - ~UserSearchDelegate(); + UserSearchDelegate(QObject* parent = 0); + virtual ~UserSearchDelegate(); + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const; private: -- cgit v0.10.2-6-g49f6