From 382bce69ae2e94a2b9635a0be6db93a6ecd4ddce Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Thu, 16 Jul 2015 09:45:52 +0200
Subject: Fix memory leaks in FileReadBytestream and FileWriteBytestream

Reported by LSAN.

Test-Information:

Detected by running FileTransferTest with LSAN on Linux.
The leak reports for the allocations in FileReadBytestream and
FileWriteBytestream are gone with this fix.

Change-Id: I32711990eca0c9a2a2982837cfac38cb11a28caa

diff --git a/Swiften/FileTransfer/FileReadBytestream.cpp b/Swiften/FileTransfer/FileReadBytestream.cpp
index 5885076..4700a9c 100644
--- a/Swiften/FileTransfer/FileReadBytestream.cpp
+++ b/Swiften/FileTransfer/FileReadBytestream.cpp
@@ -1,15 +1,17 @@
 /*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
 
-#include <boost/filesystem/fstream.hpp>
+#include <Swiften/FileTransfer/FileReadBytestream.h>
+
 #include <cassert>
-#include <boost/smart_ptr/make_shared.hpp>
+
+#include <boost/filesystem/fstream.hpp>
 #include <boost/numeric/conversion/cast.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
 
-#include <Swiften/FileTransfer/FileReadBytestream.h>
 #include <Swiften/Base/ByteArray.h>
 
 namespace Swift {
@@ -20,6 +22,7 @@ FileReadBytestream::FileReadBytestream(const boost::filesystem::path& file) : fi
 FileReadBytestream::~FileReadBytestream() {
 	if (stream) {
 		stream->close();
+		delete stream;
 		stream = NULL;
 	}
 }
diff --git a/Swiften/FileTransfer/FileWriteBytestream.cpp b/Swiften/FileTransfer/FileWriteBytestream.cpp
index 747e1de..bbf3d51 100644
--- a/Swiften/FileTransfer/FileWriteBytestream.cpp
+++ b/Swiften/FileTransfer/FileWriteBytestream.cpp
@@ -1,14 +1,15 @@
 /*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
 
-#include <boost/filesystem/fstream.hpp>
+#include <Swiften/FileTransfer/FileWriteBytestream.h>
+
 #include <cassert>
-#include <boost/numeric/conversion/cast.hpp>
 
-#include <Swiften/FileTransfer/FileWriteBytestream.h>
+#include <boost/filesystem/fstream.hpp>
+#include <boost/numeric/conversion/cast.hpp>
 
 namespace Swift {
 
@@ -18,6 +19,7 @@ FileWriteBytestream::FileWriteBytestream(const boost::filesystem::path& file) :
 FileWriteBytestream::~FileWriteBytestream() {
 	if (stream) {
 		stream->close();
+		delete stream;
 		stream = NULL;
 	}
 }
@@ -37,6 +39,7 @@ void FileWriteBytestream::write(const std::vector<unsigned char>& data) {
 void FileWriteBytestream::close() {
 	if (stream) {
 		stream->close();
+		delete stream;
 		stream = NULL;
 	}
 }
-- 
cgit v0.10.2-6-g49f6