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/Session
parentcd9c5b8d87aaae48a058ae8d498bc81d0fed82ad (diff)
downloadswift-2ef4bb560dad95555a5ae94d0bd5bff49d50d3d3.zip
swift-2ef4bb560dad95555a5ae94d0bd5bff49d50d3d3.tar.bz2
Avoid leaking connection on exit.
Diffstat (limited to 'Swiften/Session')
-rw-r--r--Swiften/Session/BasicSessionStream.cpp39
-rw-r--r--Swiften/Session/BasicSessionStream.h7
2 files changed, 24 insertions, 22 deletions
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index c4d1b6d..3f06315 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -33,23 +33,17 @@ BasicSessionStream::BasicSessionStream(
tlsContextFactory(tlsContextFactory),
timerFactory(timerFactory),
streamType(streamType),
- xmppLayer(NULL),
- connectionLayer(NULL),
compressionLayer(NULL),
tlsLayer(NULL),
whitespacePingLayer(NULL) {
-}
-
-void BasicSessionStream::initialize() {
xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, streamType);
- xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, shared_from_this(), _1));
- xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, shared_from_this(), _1));
- xmppLayer->onError.connect(boost::bind(
- &BasicSessionStream::handleXMPPError, shared_from_this()));
- xmppLayer->onDataRead.connect(boost::bind(&BasicSessionStream::handleDataRead, shared_from_this(), _1));
- xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, shared_from_this(), _1));
-
- connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionError, shared_from_this(), _1));
+ xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
+ xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
+ xmppLayer->onError.connect(boost::bind(&BasicSessionStream::handleXMPPError, this));
+ xmppLayer->onDataRead.connect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
+ xmppLayer->onWriteData.connect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
+
+ connection->onDisconnected.connect(boost::bind(&BasicSessionStream::handleConnectionError, this, _1));
connectionLayer = new ConnectionLayer(connection);
streamStack = new StreamStack(xmppLayer, connectionLayer);
@@ -59,10 +53,23 @@ void BasicSessionStream::initialize() {
BasicSessionStream::~BasicSessionStream() {
delete compressionLayer;
- delete tlsLayer;
+
+ if (tlsLayer) {
+ tlsLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleTLSError, this));
+ tlsLayer->onConnected.disconnect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
+ delete tlsLayer;
+ }
delete whitespacePingLayer;
delete streamStack;
+
+ connection->onDisconnected.disconnect(boost::bind(&BasicSessionStream::handleConnectionError, this, _1));
delete connectionLayer;
+
+ xmppLayer->onStreamStart.disconnect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
+ xmppLayer->onElement.disconnect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
+ xmppLayer->onError.disconnect(boost::bind(&BasicSessionStream::handleXMPPError, this));
+ xmppLayer->onDataRead.disconnect(boost::bind(&BasicSessionStream::handleDataRead, this, _1));
+ xmppLayer->onWriteData.disconnect(boost::bind(&BasicSessionStream::handleDataWritten, this, _1));
delete xmppLayer;
}
@@ -97,8 +104,8 @@ void BasicSessionStream::addTLSEncryption() {
}
else {
streamStack->addLayer(tlsLayer);
- tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, shared_from_this()));
- tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, shared_from_this()));
+ tlsLayer->onError.connect(boost::bind(&BasicSessionStream::handleTLSError, this));
+ tlsLayer->onConnected.connect(boost::bind(&BasicSessionStream::handleTLSConnected, this));
tlsLayer->connect();
}
}
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h
index c601792..35b5481 100644
--- a/Swiften/Session/BasicSessionStream.h
+++ b/Swiften/Session/BasicSessionStream.h
@@ -7,7 +7,6 @@
#pragma once
#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
#include "Swiften/Network/Connection.h"
#include "Swiften/Session/SessionStream.h"
@@ -25,9 +24,7 @@ namespace Swift {
class ConnectionLayer;
class CompressionLayer;
- class BasicSessionStream :
- public SessionStream,
- public boost::enable_shared_from_this<BasicSessionStream> {
+ class BasicSessionStream : public SessionStream {
public:
BasicSessionStream(
StreamType streamType,
@@ -39,8 +36,6 @@ namespace Swift {
);
~BasicSessionStream();
- void initialize();
-
virtual bool isAvailable();
virtual void writeHeader(const ProtocolHeader& header);