From 9353d3c692e1cd37bdd15b8dbe75b92be5eaa1c0 Mon Sep 17 00:00:00 2001
From: Richard Maudsley <richard.maudsley@isode.com>
Date: Tue, 22 Jul 2014 10:18:06 +0100
Subject: Fix crash when performing blocking operations after fresh login.

Test-Information:

Sign out and sign in again then try blocking a user and confirm that a crash occurs in the BlockListController. After the patch repeat sign out and sign in and confirm that crash nolonger occurs.

Change-Id: I9812097fd34f188b2ebf1d8675e47c31fdafdc06

diff --git a/Swift/Controllers/BlockListController.cpp b/Swift/Controllers/BlockListController.cpp
index 6bdb513..d778883 100644
--- a/Swift/Controllers/BlockListController.cpp
+++ b/Swift/Controllers/BlockListController.cpp
@@ -21,13 +21,14 @@
 
 namespace Swift {
 
-BlockListController::BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController) : blockListManager_(blockListManager), blockListEditorWidgetFactory_(blockListEditorWidgetFactory), blockListEditorWidget_(0), eventController_(eventController), remainingRequests_(0) {
+BlockListController::BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController) : blockListManager_(blockListManager), blockListEditorWidgetFactory_(blockListEditorWidgetFactory), blockListEditorWidget_(0), eventController_(eventController), remainingRequests_(0), uiEventStream_(uiEventStream) {
 	uiEventStream->onUIEvent.connect(boost::bind(&BlockListController::handleUIEvent, this, _1));
 	blockListManager_->getBlockList()->onItemAdded.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
 	blockListManager_->getBlockList()->onItemRemoved.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
 }
 
 BlockListController::~BlockListController() {
+	uiEventStream_->onUIEvent.disconnect(boost::bind(&BlockListController::handleUIEvent, this, _1));
 	blockListManager_->getBlockList()->onItemAdded.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
 	blockListManager_->getBlockList()->onItemRemoved.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
 }
diff --git a/Swift/Controllers/BlockListController.h b/Swift/Controllers/BlockListController.h
index 4c9caad..99c143c 100644
--- a/Swift/Controllers/BlockListController.h
+++ b/Swift/Controllers/BlockListController.h
@@ -43,6 +43,7 @@ private:
 	EventController* eventController_;
 	std::vector<JID> blockListBeforeEdit;
 	int remainingRequests_;
+	UIEventStream* uiEventStream_;
 };
 
 }
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index a16cbe7..95d8134 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -262,6 +262,8 @@ void MainController::resetClient() {
 #endif
 	delete ftOverview_;
 	ftOverview_ = NULL;
+	delete blockListController_;
+	blockListController_ = NULL;
 	delete rosterController_;
 	rosterController_ = NULL;
 	delete eventNotifier_;
-- 
cgit v0.10.2-6-g49f6