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/Client/ClientSessionStanzaChannel.cpp | |
| 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/Client/ClientSessionStanzaChannel.cpp')
| -rw-r--r-- | Swiften/Client/ClientSessionStanzaChannel.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Swiften/Client/ClientSessionStanzaChannel.cpp b/Swiften/Client/ClientSessionStanzaChannel.cpp index 3d7b9f7..3dc8c59 100644 --- a/Swiften/Client/ClientSessionStanzaChannel.cpp +++ b/Swiften/Client/ClientSessionStanzaChannel.cpp | |||
| @@ -1,18 +1,29 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <Swiften/Client/ClientSessionStanzaChannel.h> | 7 | #include <Swiften/Client/ClientSessionStanzaChannel.h> |
| 8 | 8 | ||
| 9 | #include <boost/bind.hpp> | ||
| 10 | #include <iostream> | 9 | #include <iostream> |
| 11 | 10 | ||
| 11 | #include <boost/bind.hpp> | ||
| 12 | |||
| 12 | namespace Swift { | 13 | namespace Swift { |
| 13 | 14 | ||
| 15 | ClientSessionStanzaChannel::~ClientSessionStanzaChannel() { | ||
| 16 | if (session) { | ||
| 17 | session->onFinished.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); | ||
| 18 | session->onStanzaReceived.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanza, this, _1)); | ||
| 19 | session->onStanzaAcked.disconnect(boost::bind(&ClientSessionStanzaChannel::handleStanzaAcked, this, _1)); | ||
| 20 | session->onInitialized.disconnect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); | ||
| 21 | session.reset(); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 14 | void ClientSessionStanzaChannel::setSession(boost::shared_ptr<ClientSession> session) { | 25 | void ClientSessionStanzaChannel::setSession(boost::shared_ptr<ClientSession> session) { |
| 15 | assert(!this->session); | 26 | assert(!this->session); |
| 16 | this->session = session; | 27 | this->session = session; |
| 17 | session->onInitialized.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); | 28 | session->onInitialized.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionInitialized, this)); |
| 18 | session->onFinished.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); | 29 | session->onFinished.connect(boost::bind(&ClientSessionStanzaChannel::handleSessionFinished, this, _1)); |
Swift