From 1c64e31945e80e927f87a0a94ec5ce0e00c40a7f Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Sun, 8 Feb 2015 16:40:50 +0100
Subject: Fix memory leaks reported by LSAN

Qt models are not owned by their widgets. They must be deleted manually
or a parent has to be specified for them which will take care of deletion.
The same goes for delegates and their views.

Test-Information:

Tested with Clang's leak sanitizer (part of address sanitizer). The
leak reports for the respective lines are gone with this fix.

Change-Id: Ia7407cb20ae9e4ccc2e1cf48c88877c2f87352e1

diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index d8c32be..328d837 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -123,6 +123,7 @@ MainController::MainController(
 			emoticons_(emoticons) {
 	storages_ = NULL;
 	certificateStorage_ = NULL;
+	certificateTrustChecker_ = NULL;
 	statusTracker_ = NULL;
 	presenceNotifier_ = NULL;
 	eventNotifier_ = NULL;
@@ -270,6 +271,8 @@ void MainController::resetClient() {
 	eventNotifier_ = NULL;
 	delete presenceNotifier_;
 	presenceNotifier_ = NULL;
+	delete certificateTrustChecker_;
+	certificateTrustChecker_ = NULL;
 	delete certificateStorage_;
 	certificateStorage_ = NULL;
 	delete storages_;
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 7b32bff..1d945da 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2014 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -265,6 +265,7 @@ QtSwift::~QtSwift() {
 	delete chatWindowFactory_;
 	delete certificateStorageFactory_;
 	delete storagesFactory_;
+	delete applicationPathProvider_;
 }
 
 }
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
index bade009..33863b2 100644
--- a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
@@ -4,6 +4,12 @@
  * See Documentation/Licenses/BSD-simplified.txt for more information.
  */
 
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
 #include "QtTagComboBox.h"
 
 #include <QAbstractItemView>
@@ -13,11 +19,11 @@ namespace Swift {
 
 QtTagComboBox::QtTagComboBox(QWidget* parent) : QComboBox(parent) {
 	setEditable(false);
-	displayModel = new QStandardItemModel();
+	displayModel = new QStandardItemModel(this);
 	displayItem = new QStandardItem();
 	displayItem->setText("");
 	displayModel->insertRow(0, displayItem);
-	editMenu = new QMenu();
+	editMenu = new QMenu(this);
 	this->setModel(displayModel);
 	editable = true;
 }
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
index 1069678..9b76aba 100644
--- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (c) 2014 Isode Limited.
+ * Copyright (c) 2014-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -59,6 +59,7 @@ QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* sett
 QtContactListWidget::~QtContactListWidget() {
 	delete contactListDelegate_;
 	delete removableItemDelegate_;
+	delete contactListModel_;
 }
 
 void QtContactListWidget::setList(const std::vector<Contact::ref>& list) {
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
index 151313c..2b775f9 100644
--- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
+++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (c) 2014 Isode Limited.
+ * Copyright (c) 2014-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -61,6 +61,8 @@ QtSuggestingJIDInput::QtSuggestingJIDInput(QWidget* parent, SettingsProvider* se
 QtSuggestingJIDInput::~QtSuggestingJIDInput() {
 	settings_->onSettingChanged.disconnect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
 	delete treeViewPopup_;
+	delete contactListDelegate_;
+	delete contactListModel_;
 }
 
 Contact::ref QtSuggestingJIDInput::getContact() {
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 323bb43..d2f8b7a 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2012 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -86,6 +86,7 @@ Client::~Client() {
 	delete whiteboardSessionManager;
 
 	delete fileTransferManager;
+	delete blockListManager;
 	delete jingleSessionManager;
 	
 	delete blindCertificateTrustChecker;
@@ -125,6 +126,7 @@ void Client::setSoftwareVersion(const std::string& name, const std::string& vers
 }
 
 void Client::handleConnected() {
+	delete fileTransferManager;
 #ifdef SWIFT_EXPERIMENTAL_FT
 	fileTransferManager = new FileTransferManagerImpl(
 			getJID(), 
diff --git a/Swiften/FileTransfer/FileTransferManagerImpl.cpp b/Swiften/FileTransfer/FileTransferManagerImpl.cpp
index fe8bfd6..f439197 100644
--- a/Swiften/FileTransfer/FileTransferManagerImpl.cpp
+++ b/Swiften/FileTransfer/FileTransferManagerImpl.cpp
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (c) 2013-2014 Isode Limited.
+ * Copyright (c) 2013-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -86,10 +86,12 @@ FileTransferManagerImpl::FileTransferManagerImpl(
 }
 
 FileTransferManagerImpl::~FileTransferManagerImpl() {
-	delete s5bServerManager;
 	delete incomingFTManager;
 	delete outgoingFTManager;
 	delete transporterFactory;
+	delete bytestreamProxy;
+	delete s5bServerManager;
+	delete bytestreamRegistry;
 }
 
 void FileTransferManagerImpl::start() {
-- 
cgit v0.10.2-6-g49f6