diff options
author | Tobias Markmann <tm@ayena.de> | 2015-06-30 07:02:01 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-07-07 19:58:12 (GMT) |
commit | 799a7ac203dc2576872894dfdd1adb5cdbbacf7b (patch) | |
tree | e0242decf49222b83674143cf04f61c3dc01bc35 /Swiften/FileTransfer | |
parent | abd96284e162b3594bd0fc90a5da6b78709dee23 (diff) | |
download | swift-799a7ac203dc2576872894dfdd1adb5cdbbacf7b.zip swift-799a7ac203dc2576872894dfdd1adb5cdbbacf7b.tar.bz2 |
Fix memory leaks reported by ASAN
Test-Information:
Tested on Elementary OS with a LLVM/Clang 3.7.0 build. With this patch
the reports for the fixed locations are gone.
Change-Id: I0260fc85ad662335a69ace331f51ebe2f864ef97
Diffstat (limited to 'Swiften/FileTransfer')
6 files changed, 68 insertions, 44 deletions
diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp index 877b2fd..39da46f 100644 --- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp @@ -12,20 +12,20 @@ #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/StringCodecs/Base64.h> #include <Swiften/Base/foreach.h> -#include <Swiften/Jingle/JingleSession.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Elements/JingleFileTransferHash.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> -#include <Swiften/Elements/JingleFileTransferHash.h> -#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/FileTransfer/FileTransferTransporterFactory.h> +#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> +#include <Swiften/FileTransfer/TransportSession.h> #include <Swiften/FileTransfer/WriteBytestream.h> -#include <Swiften/Elements/JingleFileTransferDescription.h> +#include <Swiften/Jingle/JingleSession.h> #include <Swiften/Network/TimerFactory.h> #include <Swiften/Queries/GenericRequest.h> -#include <Swiften/FileTransfer/TransportSession.h> +#include <Swiften/StringCodecs/Base64.h> using namespace Swift; @@ -56,6 +56,8 @@ IncomingJingleFileTransfer::IncomingJingleFileTransfer( } IncomingJingleFileTransfer::~IncomingJingleFileTransfer() { + delete hashCalculator; + hashCalculator = NULL; } void IncomingJingleFileTransfer::accept( @@ -334,8 +336,7 @@ void IncomingJingleFileTransfer::stopAll() { case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break; } if (state != Initial) { - delete transporter; - transporter = NULL; + removeTransporter(); } } diff --git a/Swiften/FileTransfer/JingleFileTransfer.cpp b/Swiften/FileTransfer/JingleFileTransfer.cpp index dbc4391..cf67a67 100644 --- a/Swiften/FileTransfer/JingleFileTransfer.cpp +++ b/Swiften/FileTransfer/JingleFileTransfer.cpp @@ -8,13 +8,13 @@ #include <boost/typeof/typeof.hpp> +#include <Swiften/Base/Log.h> #include <Swiften/Base/foreach.h> -#include <Swiften/JID/JID.h> #include <Swiften/Crypto/CryptoProvider.h> -#include <Swiften/StringCodecs/Hexify.h> -#include <Swiften/Jingle/JingleSession.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> -#include <Swiften/Base/Log.h> +#include <Swiften/JID/JID.h> +#include <Swiften/Jingle/JingleSession.h> +#include <Swiften/StringCodecs/Hexify.h> using namespace Swift; @@ -213,6 +213,7 @@ void JingleFileTransfer::handleTransportInfoReceived( } void JingleFileTransfer::setTransporter(FileTransferTransporter* transporter) { + SWIFT_LOG_ASSERT(!this->transporter, error); this->transporter = transporter; localTransportCandidatesGeneratedConnection = transporter->onLocalCandidatesGenerated.connect( boost::bind(&JingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1, _2, _3)); @@ -222,3 +223,13 @@ void JingleFileTransfer::setTransporter(FileTransferTransporter* transporter) { boost::bind(&JingleFileTransfer::handleProxyActivateFinished, this, _1, _2)); } +void JingleFileTransfer::removeTransporter() { + if (transporter) { + localTransportCandidatesGeneratedConnection.release(); + remoteTransportCandidateSelectFinishedConnection.release(); + proxyActivatedConnection.release(); + delete transporter; + transporter = NULL; + } +} + diff --git a/Swiften/FileTransfer/JingleFileTransfer.h b/Swiften/FileTransfer/JingleFileTransfer.h index aabeec2..16a55c6 100644 --- a/Swiften/FileTransfer/JingleFileTransfer.h +++ b/Swiften/FileTransfer/JingleFileTransfer.h @@ -6,10 +6,11 @@ #pragma once -#include <Swiften/Base/API.h> +#include <vector> #include <boost/shared_ptr.hpp> -#include <vector> + +#include <Swiften/Base/API.h> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/ErrorPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> @@ -64,6 +65,7 @@ namespace Swift { typedef std::map<std::string, JingleS5BTransportPayload::Candidate> CandidateMap; void setTransporter(FileTransferTransporter* transporter); + void removeTransporter(); void fillCandidateMap( CandidateMap& map, const std::vector<JingleS5BTransportPayload::Candidate>&); diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index aabbd2d..5c18b13 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2013-2015 Isode Limited. + * Copyright (c) 2013-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -21,25 +21,24 @@ #include <boost/smart_ptr/make_shared.hpp> #include <boost/typeof/typeof.hpp> -#include <Swiften/Base/foreach.h> #include <Swiften/Base/IDGenerator.h> -#include <Swiften/Jingle/JingleContentID.h> -#include <Swiften/Jingle/JingleSession.h> +#include <Swiften/Base/Log.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Crypto/CryptoProvider.h> #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/JingleFileTransferHash.h> -#include <Swiften/Elements/JingleTransportPayload.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> -#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> +#include <Swiften/Elements/JingleTransportPayload.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/FileTransfer/FileTransferTransporterFactory.h> +#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> #include <Swiften/FileTransfer/ReadBytestream.h> #include <Swiften/FileTransfer/TransportSession.h> -#include <Swiften/Crypto/CryptoProvider.h> +#include <Swiften/Jingle/JingleContentID.h> +#include <Swiften/Jingle/JingleSession.h> #include <Swiften/Network/TimerFactory.h> -#include <Swiften/Base/Log.h> - using namespace Swift; static const int DEFAULT_BLOCK_SIZE = 4096; @@ -78,11 +77,16 @@ OutgoingJingleFileTransfer::~OutgoingJingleFileTransfer() { stream->onRead.disconnect( boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1)); delete hashCalculator; + hashCalculator = NULL; + removeTransporter(); } void OutgoingJingleFileTransfer::start() { SWIFT_LOG(debug) << std::endl; - if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } + if (state != Initial) { + SWIFT_LOG(warning) << "Incorrect state" << std::endl; + return; + } setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options)); setState(GeneratingInitialLocalCandidates); @@ -290,7 +294,7 @@ void OutgoingJingleFileTransfer::stopAll() { case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break; } if (state != Initial) { - delete transporter; + removeTransporter(); } } diff --git a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp index aaf90ea..54d2c88 100644 --- a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp +++ b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp @@ -10,39 +10,39 @@ * See the COPYING file for more information. */ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> +#include <iostream> #include <boost/smart_ptr/make_shared.hpp> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + #include <Swiften/Base/ByteArray.h> -#include <Swiften/Base/Override.h> #include <Swiften/Base/Log.h> +#include <Swiften/Base/Override.h> #include <Swiften/Client/DummyStanzaChannel.h> +#include <Swiften/Crypto/CryptoProvider.h> +#include <Swiften/Crypto/PlatformCryptoProvider.h> #include <Swiften/Elements/IBB.h> +#include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> #include <Swiften/Elements/JingleS5BTransportPayload.h> -#include <Swiften/Elements/JingleFileTransferDescription.h> -#include <Swiften/FileTransfer/DefaultFileTransferTransporterFactory.h> +#include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/FileTransfer/ByteArrayWriteBytestream.h> +#include <Swiften/FileTransfer/DefaultFileTransferTransporterFactory.h> #include <Swiften/FileTransfer/IncomingJingleFileTransfer.h> -#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> -#include <Swiften/Network/PlatformNetworkEnvironment.h> -#include <Swiften/Network/StaticDomainNameResolver.h> #include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> #include <Swiften/FileTransfer/SOCKS5BytestreamServerManager.h> #include <Swiften/Jingle/FakeJingleSession.h> -#include <Swiften/Network/NATTraverser.h> -#include <Swiften/Network/DummyTimerFactory.h> -#include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/Network/DummyConnectionFactory.h> #include <Swiften/Network/DummyConnectionServerFactory.h> +#include <Swiften/Network/DummyTimerFactory.h> +#include <Swiften/Network/NATTraverser.h> #include <Swiften/Network/PlatformNATTraversalWorker.h> +#include <Swiften/Network/PlatformNetworkEnvironment.h> +#include <Swiften/Network/StaticDomainNameResolver.h> #include <Swiften/Queries/IQRouter.h> -#include <Swiften/Crypto/CryptoProvider.h> -#include <Swiften/Crypto/PlatformCryptoProvider.h> - -#include <iostream> using namespace Swift; using namespace boost; @@ -89,8 +89,11 @@ public: void tearDown() { delete ftTransporterFactory; + delete networkEnvironment; + delete natTraverser; delete bytestreamServerManager; delete bytestreamProxy; + delete serverConnectionFactory; delete connectionFactory; delete timerFactory; delete bytestreamRegistry; diff --git a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp index 0186e0b..40e7233 100644 --- a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp +++ b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp @@ -10,13 +10,15 @@ * See the COPYING file for more information. */ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> +#include <iostream> #include <boost/bind.hpp> #include <boost/optional.hpp> #include <boost/smart_ptr/make_shared.hpp> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + #include <Swiften/Base/ByteArray.h> #include <Swiften/Base/IDGenerator.h> #include <Swiften/Base/Override.h> @@ -47,8 +49,6 @@ #include <Swiften/Network/PlatformNetworkEnvironment.h> #include <Swiften/Queries/IQRouter.h> -#include <iostream> - using namespace Swift; class OutgoingJingleFileTransferTest : public CppUnit::TestFixture { @@ -123,10 +123,13 @@ public: void tearDown() { delete ftTransportFactory; + delete networkEnvironment; + delete natTraverser; delete bytestreamServerManager; delete s5bProxy; delete idGen; delete s5bRegistry; + delete serverConnectionFactory; delete connectionFactory; delete timerFactory; delete eventLoop; |