From 54b16ff807d7f70ac7633292d773b7affece1c43 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 6 Mar 2012 08:59:26 +0000 Subject: don't crash if an AdHoc is deleted while inflight diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp index ecc6cd0..cd6b4a3 100644 --- a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp @@ -17,6 +17,10 @@ OutgoingAdHocCommandSession::OutgoingAdHocCommandSession(const JID& to, const st } +OutgoingAdHocCommandSession::~OutgoingAdHocCommandSession() { + connection_.disconnect(); +} + void OutgoingAdHocCommandSession::handleResponse(boost::shared_ptr payload, ErrorPayload::ref error) { if (error) { onError(error); @@ -58,7 +62,7 @@ bool OutgoingAdHocCommandSession::getIsMultiStage() const { void OutgoingAdHocCommandSession::start() { boost::shared_ptr > commandRequest = boost::make_shared< GenericRequest >(IQ::Set, to_, boost::make_shared(commandNode_), iqRouter_); - commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + connection_ = commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); commandRequest->send(); } @@ -84,7 +88,8 @@ void OutgoingAdHocCommandSession::submitForm(Form::ref form, Command::Action act boost::shared_ptr command(boost::make_shared(commandNode_, sessionID_, action)); command->setForm(form); boost::shared_ptr > commandRequest = boost::make_shared< GenericRequest >(IQ::Set, to_, command, iqRouter_); - commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); + connection_.disconnect(); + connection_ = commandRequest->onResponse.connect(boost::bind(&OutgoingAdHocCommandSession::handleResponse, this, _1, _2)); commandRequest->send(); } diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.h b/Swiften/AdHoc/OutgoingAdHocCommandSession.h index a64eb4e..7c7cc99 100644 --- a/Swiften/AdHoc/OutgoingAdHocCommandSession.h +++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace Swift { class IQRouter; @@ -33,6 +34,7 @@ namespace Swift { EnabledAndPresent = 3}; OutgoingAdHocCommandSession(const JID& to, const std::string& commandNode, IQRouter* iqRouter); + ~OutgoingAdHocCommandSession(); /** * Send initial request to the target. */ @@ -91,5 +93,6 @@ namespace Swift { bool isMultiStage_; std::string sessionID_; std::map actionStates_; + boost::bsignals::connection connection_; }; } -- cgit v0.10.2-6-g49f6