diff options
author | Tobias Markmann <tm@ayena.de> | 2015-10-06 07:30:56 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-10-14 14:35:55 (GMT) |
commit | b00c84574fc730eeeabb57df1f17b54855218193 (patch) | |
tree | bbc05725a01a12b832065beb9f5eb20d71cb3178 | |
parent | a30c7ad74fc830dbd10b9560054f39063b5e8372 (diff) | |
download | swift-b00c84574fc730eeeabb57df1f17b54855218193.zip swift-b00c84574fc730eeeabb57df1f17b54855218193.tar.bz2 |
Fix memory leak warnings by Valgrind/LSAN
Test-Information:
Both Valgrind and clang's leak sanitizer report a lot leaks
on the FileTransferTest. With this commit it the stack traces
related to the fixed leaks are gone.
Change-Id: Idae9a81bcd8d97576d3f1469bf64490e0bfa7d55
5 files changed, 33 insertions, 18 deletions
diff --git a/Swiften/Disco/DiscoServiceWalker.cpp b/Swiften/Disco/DiscoServiceWalker.cpp index f84262b..5803602 100644 --- a/Swiften/Disco/DiscoServiceWalker.cpp +++ b/Swiften/Disco/DiscoServiceWalker.cpp @@ -1,16 +1,16 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Disco/DiscoServiceWalker.h> +#include <boost/bind.hpp> + #include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> -#include <boost/bind.hpp> - namespace Swift { DiscoServiceWalker::DiscoServiceWalker(const JID& service, IQRouter* iqRouter, size_t maxSteps) : service_(service), iqRouter_(iqRouter), maxSteps_(maxSteps), active_(false) { @@ -57,6 +57,7 @@ void DiscoServiceWalker::handleDiscoInfoResponse(boost::shared_ptr<DiscoInfo> in SWIFT_LOG(debug) << "Disco info response from " << request->getReceiver() << std::endl; + request->onResponse.disconnect(boost::bind(&DiscoServiceWalker::handleDiscoInfoResponse, this, _1, _2, request)); pendingDiscoInfoRequests_.erase(request); if (error) { handleDiscoError(request->getReceiver(), error); @@ -91,6 +92,7 @@ void DiscoServiceWalker::handleDiscoItemsResponse(boost::shared_ptr<DiscoItems> } SWIFT_LOG(debug) << "Received disco items from " << request->getReceiver() << std::endl; + request->onResponse.disconnect(boost::bind(&DiscoServiceWalker::handleDiscoItemsResponse, this, _1, _2, request)); pendingDiscoItemsRequests_.erase(request); if (error) { handleDiscoError(request->getReceiver(), error); diff --git a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp index dffc39b..ca29898 100644 --- a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp +++ b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp @@ -73,7 +73,12 @@ DefaultFileTransferTransporter::DefaultFileTransferTransporter( DefaultFileTransferTransporter::~DefaultFileTransferTransporter() { stopGeneratingLocalCandidates(); + remoteCandidateSelector->onCandidateSelectFinished.disconnect( + boost::bind(&DefaultFileTransferTransporter::handleRemoteCandidateSelectFinished, this, _1, _2)); delete remoteCandidateSelector; + + localCandidateGenerator->onLocalTransportCandidatesGenerated.disconnect( + boost::bind(&DefaultFileTransferTransporter::handleLocalCandidatesGenerated, this, _1)); delete localCandidateGenerator; } diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp index 04d5d86..a38501b 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp @@ -42,6 +42,8 @@ SOCKS5BytestreamClientSession::SOCKS5BytestreamClientSession( } SOCKS5BytestreamClientSession::~SOCKS5BytestreamClientSession() { + weFailedTimeout->onTick.disconnect( + boost::bind(&SOCKS5BytestreamClientSession::handleWeFailedTimeout, this)); weFailedTimeout->stop(); } diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp index 25a12ea..3221790 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp @@ -113,6 +113,7 @@ boost::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager: } void SOCKS5BytestreamProxiesManager::handleProxiesFound(std::vector<S5BProxyRequest::ref> proxyHosts) { + proxyFinder_->onProxiesFound.disconnect(boost::bind(&SOCKS5BytestreamProxiesManager::handleProxiesFound, this, _1)); foreach(S5BProxyRequest::ref proxy, proxyHosts) { if (proxy) { if (HostAddress(proxy->getStreamHost().get().host).isValid()) { diff --git a/Swiften/QA/FileTransferTest/FileTransferTest.cpp b/Swiften/QA/FileTransferTest/FileTransferTest.cpp index 2d2d6c8..8faf8a9 100644 --- a/Swiften/QA/FileTransferTest/FileTransferTest.cpp +++ b/Swiften/QA/FileTransferTest/FileTransferTest.cpp @@ -7,28 +7,28 @@ #include <fstream> #include <boost/algorithm/string.hpp> -#include <boost/numeric/conversion/cast.hpp> #include <boost/filesystem.hpp> +#include <boost/numeric/conversion/cast.hpp> -#include <Swiften/Base/sleep.h> -#include <Swiften/Base/foreach.h> +#include <Swiften/Base/BoostRandomGenerator.h> +#include <Swiften/Base/Debug.h> #include <Swiften/Base/Log.h> -#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/sleep.h> #include <Swiften/Client/Client.h> -#include <Swiften/EventLoop/SimpleEventLoop.h> -#include <Swiften/Network/BoostNetworkFactories.h> -#include <Swiften/Network/Timer.h> -#include <Swiften/Network/TimerFactory.h> +#include <Swiften/Client/ClientXMLTracer.h> +#include <Swiften/Disco/ClientDiscoManager.h> #include <Swiften/Disco/EntityCapsProvider.h> #include <Swiften/Elements/Presence.h> -#include <Swiften/FileTransfer/ReadBytestream.h> -#include <Swiften/Base/BoostRandomGenerator.h> +#include <Swiften/EventLoop/SimpleEventLoop.h> #include <Swiften/FileTransfer/FileReadBytestream.h> -#include <Swiften/FileTransfer/OutgoingFileTransfer.h> #include <Swiften/FileTransfer/FileTransferManager.h> -#include <Swiften/Disco/ClientDiscoManager.h> #include <Swiften/FileTransfer/FileWriteBytestream.h> -#include <Swiften/Base/Debug.h> +#include <Swiften/FileTransfer/OutgoingFileTransfer.h> +#include <Swiften/FileTransfer/ReadBytestream.h> +#include <Swiften/Network/BoostNetworkFactories.h> +#include <Swiften/Network/Timer.h> +#include <Swiften/Network/TimerFactory.h> using namespace Swift; @@ -59,8 +59,8 @@ class FileTransferTest { receiver_->onConnected.connect(boost::bind(&FileTransferTest::handleReceiverConnected, this)); receiver_->onDisconnected.connect(boost::bind(&FileTransferTest::handleReceiverDisconnected, this, _1)); - new ClientXMLTracer(sender_.get()); - new ClientXMLTracer(receiver_.get()); + senderTracer_ = new ClientXMLTracer(sender_.get()); + receiverTracer_ = new ClientXMLTracer(receiver_.get()); ClientOptions options; options.useTLS = ClientOptions::NeverUseTLS; @@ -92,6 +92,9 @@ class FileTransferTest { ~FileTransferTest() { timeOut_->stop(); + delete senderTracer_; + delete receiverTracer_; + if(boost::filesystem::exists(sendFilePath_)) { boost::filesystem::remove(sendFilePath_); } @@ -239,6 +242,7 @@ class FileTransferTest { private: int senderCandidates_; boost::shared_ptr<Client> sender_; + ClientXMLTracer* senderTracer_; ByteArray sendData_; OutgoingFileTransfer::ref outgoingFileTransfer_; boost::filesystem::path sendFilePath_; @@ -247,6 +251,7 @@ class FileTransferTest { int receiverCandidates_; boost::shared_ptr<Client> receiver_; + ClientXMLTracer* receiverTracer_; ByteArray receiveData_; std::vector<IncomingFileTransfer::ref> incomingFileTransfers_; boost::filesystem::path receiveFilePath_; |