diff options
author | Tobias Markmann <tm@ayena.de> | 2015-07-21 16:30:15 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-07-21 16:42:34 (GMT) |
commit | 6ca201d0b48f4273e24dd7bff17c4a46eeaddf39 (patch) | |
tree | ace238716521c89a54168472905379a9249c3666 /Swiften/Network | |
parent | 02ecf91d261276ec6f1e46b537ac0e10ebae3170 (diff) | |
download | swift-6ca201d0b48f4273e24dd7bff17c4a46eeaddf39.zip swift-6ca201d0b48f4273e24dd7bff17c4a46eeaddf39.tar.bz2 |
Explicitly disconnect from remaining resources in destructors
Explicitly disconnect from remaining resources in the
ChainedConnected and ClientSessionStanzaChannel destructors, so
the event loop will not call the signal handler methods on a
freed object.
Test-Information:
Repeating the test case of creating a Swift::Client instance,
connecting it and then deleting it after a random time below one
second.
On Mac OS X 10.9.5 running this test case causes two ASAN
heap-use-after-free errors and with this patch the errors are
gone.
Change-Id: I3e48150c3633f4076ca9172aad9e85ba389df950
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/ChainedConnector.cpp | 15 | ||||
-rw-r--r-- | Swiften/Network/ChainedConnector.h | 10 |
2 files changed, 18 insertions, 7 deletions
diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp index ac48d20..3cc4057 100644 --- a/Swiften/Network/ChainedConnector.cpp +++ b/Swiften/Network/ChainedConnector.cpp @@ -1,18 +1,19 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/ChainedConnector.h> -#include <boost/bind.hpp> #include <typeinfo> +#include <boost/bind.hpp> + #include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> -#include <Swiften/Network/Connector.h> #include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/Network/Connector.h> using namespace Swift; @@ -32,6 +33,14 @@ ChainedConnector::ChainedConnector( timeoutMilliseconds(0) { } +ChainedConnector::~ChainedConnector() { + if (currentConnector) { + currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2)); + currentConnector->stop(); + currentConnector.reset(); + } +} + void ChainedConnector::setTimeoutMilliseconds(int milliseconds) { timeoutMilliseconds = milliseconds; } diff --git a/Swiften/Network/ChainedConnector.h b/Swiften/Network/ChainedConnector.h index 77fa6fd..9bcc961 100644 --- a/Swiften/Network/ChainedConnector.h +++ b/Swiften/Network/ChainedConnector.h @@ -1,20 +1,21 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <deque> #include <string> #include <vector> -#include <deque> -#include <boost/shared_ptr.hpp> + #include <boost/optional.hpp> +#include <boost/shared_ptr.hpp> #include <Swiften/Base/API.h> -#include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/Error.h> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class Connection; @@ -26,6 +27,7 @@ namespace Swift { class SWIFTEN_API ChainedConnector { public: ChainedConnector(const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver*, const std::vector<ConnectionFactory*>&, TimerFactory*); + ~ChainedConnector(); void setTimeoutMilliseconds(int milliseconds); void start(); |