From 8a5230c10571f7bb52967d672008ccf603391f2f Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Sat, 18 Feb 2017 00:50:51 +0100 Subject: Disconnect signals in ComponentSessionStanzaChannel dtor This is similar to what is currently already done in the dtor of ClientSessionStanzaChannel. This should fix potential crashes that have been reported in Sluift with ASAN enabled, showing a heap-use-after-free in ComponentSessionStanzaChannel::handleSessionFinished. Test-Information: All unit tests pass successfully on macOS 10.12.3 with clang-5.0. Change-Id: Id1e95894f9d5fe85922c0e11d18a38d46bd08e3c diff --git a/Swiften/Component/ComponentSessionStanzaChannel.cpp b/Swiften/Component/ComponentSessionStanzaChannel.cpp index fd61594..e4bf231 100644 --- a/Swiften/Component/ComponentSessionStanzaChannel.cpp +++ b/Swiften/Component/ComponentSessionStanzaChannel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -12,6 +12,15 @@ namespace Swift { +ComponentSessionStanzaChannel::~ComponentSessionStanzaChannel() { + if (session) { + session->onInitialized.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleSessionInitialized, this)); + session->onFinished.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleSessionFinished, this, _1)); + session->onStanzaReceived.disconnect(boost::bind(&ComponentSessionStanzaChannel::handleStanza, this, _1)); + session.reset(); + } +} + void ComponentSessionStanzaChannel::setSession(std::shared_ptr session) { assert(!this->session); this->session = session; diff --git a/Swiften/Component/ComponentSessionStanzaChannel.h b/Swiften/Component/ComponentSessionStanzaChannel.h index ad38edc..d8a4501 100644 --- a/Swiften/Component/ComponentSessionStanzaChannel.h +++ b/Swiften/Component/ComponentSessionStanzaChannel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -22,6 +22,8 @@ namespace Swift { */ class SWIFTEN_API ComponentSessionStanzaChannel : public StanzaChannel { public: + virtual ~ComponentSessionStanzaChannel(); + void setSession(std::shared_ptr session); void sendIQ(std::shared_ptr iq); -- cgit v0.10.2-6-g49f6