From a2b065eb22755f9341c58096805875021faffa67 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Fri, 19 Jun 2015 14:45:31 +0200
Subject: Stop timer when SOCKS5BytestreamClientSession is deleted

ASAN reported heap-use-after-free because if the timer is running
and an instance is freed, the signal of the timer is still emitted and
connected slots are called.

Test-Information:

Tested that the ASAN report wents away with this fix.

Change-Id: Id785737c4c015e5c638e9d9f6419d740d6cf83b9

diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
index 4a0cd67..04d5d86 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
@@ -16,13 +16,13 @@
 #include <boost/numeric/conversion/cast.hpp>
 
 #include <Swiften/Base/Algorithm.h>
-#include <Swiften/Base/SafeByteArray.h>
+#include <Swiften/Base/ByteArray.h>
 #include <Swiften/Base/Concat.h>
 #include <Swiften/Base/Log.h>
-#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Base/SafeByteArray.h>
 #include <Swiften/FileTransfer/BytestreamException.h>
 #include <Swiften/Network/TimerFactory.h>
-#include <Swiften/Base/ByteArray.h>
+#include <Swiften/StringCodecs/Hexify.h>
 
 namespace Swift {
 
@@ -42,6 +42,7 @@ SOCKS5BytestreamClientSession::SOCKS5BytestreamClientSession(
 }
 
 SOCKS5BytestreamClientSession::~SOCKS5BytestreamClientSession() {
+	weFailedTimeout->stop();
 }
 
 void SOCKS5BytestreamClientSession::start() {
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
index cf731c1..1c0563a 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.h
@@ -4,16 +4,22 @@
  * See Documentation/Licenses/BSD-simplified.txt for more information.
  */
 
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
 #pragma once
 
-#include <boost/shared_ptr.hpp>
 #include <boost/optional.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include <Swiften/Base/API.h>
 #include <Swiften/Base/ByteArray.h>
 #include <Swiften/FileTransfer/FileTransferError.h>
-#include <Swiften/FileTransfer/WriteBytestream.h>
 #include <Swiften/FileTransfer/ReadBytestream.h>
+#include <Swiften/FileTransfer/WriteBytestream.h>
 #include <Swiften/JID/JID.h>
 #include <Swiften/Network/Connection.h>
 #include <Swiften/Network/HostAddressPort.h>
@@ -96,10 +102,10 @@ private:
 
 	Timer::ref weFailedTimeout;
 
-	boost::bsignals::connection connectFinishedConnection;
-	boost::bsignals::connection dataWrittenConnection;
-	boost::bsignals::connection dataReadConnection;
-	boost::bsignals::connection disconnectedConnection;
+	boost::bsignals::scoped_connection connectFinishedConnection;
+	boost::bsignals::scoped_connection dataWrittenConnection;
+	boost::bsignals::scoped_connection dataReadConnection;
+	boost::bsignals::scoped_connection disconnectedConnection;
 };
 
 }
-- 
cgit v0.10.2-6-g49f6