summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2017-05-04 17:55:18 (GMT)
committerKevin Smith <kevin.smith@isode.com>2017-05-05 16:36:29 (GMT)
commit3932697b0d4c9ca01e6d1d2ae84e7f386389e099 (patch)
tree3f207f135ef2f99fcc0de0ca2b9c6a6964f9746f
parentf033fc54d5cd549822a3462bf0dfcc852e7b4dee (diff)
downloadswift-3932697b0d4c9ca01e6d1d2ae84e7f386389e099.zip
swift-3932697b0d4c9ca01e6d1d2ae84e7f386389e099.tar.bz2
Fix SendFile example heap-use-after-free
This fixes the crash by moving Swift::Client to a unique_ptr. By specifying the order the objects will be destructed, we avoid accessing the Socks5ByteStreamProxiesManager instance after it has been destroyed. Also there is no need reset the outgoingFileTransfer pointer. Test Information: Use the SendFile example to send a file to a user connected with Swift. Change-Id: I0462dc60c1d4d5eb3b07516c6e609bbe70954039
-rw-r--r--Swiften/Examples/SendFile/SendFile.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/Swiften/Examples/SendFile/SendFile.cpp b/Swiften/Examples/SendFile/SendFile.cpp
index 0e1fb23..2b701c7 100644
--- a/Swiften/Examples/SendFile/SendFile.cpp
+++ b/Swiften/Examples/SendFile/SendFile.cpp
@@ -41,4 +41,3 @@ class FileSender {
public:
- FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file), tracer(nullptr) {
- client = new Swift::Client(jid, password, &networkFactories);
+ FileSender(const JID& jid, const std::string& password, const JID& recipient, const boost::filesystem::path& file) : jid(jid), password(password), recipient(recipient), file(file), tracer(nullptr), client(std::unique_ptr<Swift::Client>(new Swift::Client(jid, password, &networkFactories))) {
client->onConnected.connect(boost::bind(&FileSender::handleConnected, this));
@@ -53,3 +52,2 @@ class FileSender {
client->onConnected.disconnect(boost::bind(&FileSender::handleConnected, this));
- delete client;
}
@@ -97,3 +95,2 @@ class FileSender {
std::cout << "File transfer finished." << std::endl;
- outgoingFileTransfer.reset();
if (error) {
@@ -120,4 +117,4 @@ class FileSender {
boost::filesystem::path file;
- Client* client;
ClientXMLTracer* tracer;
+ std::unique_ptr<Swift::Client> client;
};