summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-12-27 15:10:27 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-12-27 15:24:23 (GMT)
commit2ef4bb560dad95555a5ae94d0bd5bff49d50d3d3 (patch)
tree79a7eceecc4afe8785323983a1e4496dd52d7dd8 /Swiften/Client
parentcd9c5b8d87aaae48a058ae8d498bc81d0fed82ad (diff)
downloadswift-contrib-2ef4bb560dad95555a5ae94d0bd5bff49d50d3d3.zip
swift-contrib-2ef4bb560dad95555a5ae94d0bd5bff49d50d3d3.tar.bz2
Avoid leaking connection on exit.
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/ClientSession.h4
-rw-r--r--Swiften/Client/CoreClient.cpp8
2 files changed, 7 insertions, 5 deletions
diff --git a/Swiften/Client/ClientSession.h b/Swiften/Client/ClientSession.h
index 170491f..b779735 100644
--- a/Swiften/Client/ClientSession.h
+++ b/Swiften/Client/ClientSession.h
@@ -81,6 +81,10 @@ namespace Swift {
void start();
void finish();
+ bool isFinished() const {
+ return getState() == Finished;
+ }
+
void sendCredentials(const String& password);
void sendStanza(boost::shared_ptr<Stanza>);
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 7b1f3fd..46b4cbb 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -34,7 +34,7 @@ CoreClient::CoreClient(EventLoop* eventLoop, NetworkFactories* networkFactories,
}
CoreClient::~CoreClient() {
- if (session_ || connection_) {
+ if ((session_ && !session_->isFinished()) || connection_) {
std::cerr << "Warning: Client not disconnected properly" << std::endl;
}
delete tlsFactories;
@@ -79,7 +79,6 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
}
sessionStream_->onDataRead.connect(boost::bind(&CoreClient::handleDataRead, this, _1));
sessionStream_->onDataWritten.connect(boost::bind(&CoreClient::handleDataWritten, this, _1));
- sessionStream_->initialize();
session_ = ClientSession::create(jid_, sessionStream_);
session_->setCertificateTrustChecker(certificateTrustChecker);
@@ -94,7 +93,7 @@ void CoreClient::disconnect() {
// FIXME: We should be able to do without this boolean. We just have to make sure we can tell the difference between
// connector finishing without a connection due to an error or because of a disconnect.
disconnectRequested_ = true;
- if (session_) {
+ if (!session_->isFinished()) {
session_->finish();
}
else if (connector_) {
@@ -109,7 +108,6 @@ void CoreClient::setCertificate(const String& certificate) {
void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) {
session_->onFinished.disconnect(boost::bind(&CoreClient::handleSessionFinished, this, _1));
session_->onNeedCredentials.disconnect(boost::bind(&CoreClient::handleNeedCredentials, this));
- session_.reset();
sessionStream_->onDataRead.disconnect(boost::bind(&CoreClient::handleDataRead, this, _1));
sessionStream_->onDataWritten.disconnect(boost::bind(&CoreClient::handleDataWritten, this, _1));
@@ -244,7 +242,7 @@ void CoreClient::sendPresence(boost::shared_ptr<Presence> presence) {
}
bool CoreClient::isActive() const {
- return session_ || connector_;
+ return (session_ && !session_->isFinished()) || connector_;
}
void CoreClient::setCertificateTrustChecker(CertificateTrustChecker* checker) {