diff options
| author | Tobias Markmann <tm@ayena.de> | 2015-07-16 07:45:52 (GMT) |
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2015-07-16 07:45:52 (GMT) |
| commit | 382bce69ae2e94a2b9635a0be6db93a6ecd4ddce (patch) | |
| tree | bab5e32775850da033313e74d7683da10c896d0b | |
| parent | 2c8a390256a9ef0c0d8c6c930594a68d8f6d2072 (diff) | |
| download | swift-382bce69ae2e94a2b9635a0be6db93a6ecd4ddce.zip swift-382bce69ae2e94a2b9635a0be6db93a6ecd4ddce.tar.bz2 | |
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
| -rw-r--r-- | Swiften/FileTransfer/FileReadBytestream.cpp | 11 | ||||
| -rw-r--r-- | Swiften/FileTransfer/FileWriteBytestream.cpp | 11 |
2 files changed, 14 insertions, 8 deletions
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,27 +1,30 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2013 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <boost/filesystem/fstream.hpp> | 7 | #include <Swiften/FileTransfer/FileReadBytestream.h> |
| 8 | |||
| 8 | #include <cassert> | 9 | #include <cassert> |
| 9 | #include <boost/smart_ptr/make_shared.hpp> | 10 | |
| 11 | #include <boost/filesystem/fstream.hpp> | ||
| 10 | #include <boost/numeric/conversion/cast.hpp> | 12 | #include <boost/numeric/conversion/cast.hpp> |
| 13 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 11 | 14 | ||
| 12 | #include <Swiften/FileTransfer/FileReadBytestream.h> | ||
| 13 | #include <Swiften/Base/ByteArray.h> | 15 | #include <Swiften/Base/ByteArray.h> |
| 14 | 16 | ||
| 15 | namespace Swift { | 17 | namespace Swift { |
| 16 | 18 | ||
| 17 | FileReadBytestream::FileReadBytestream(const boost::filesystem::path& file) : file(file), stream(NULL) { | 19 | FileReadBytestream::FileReadBytestream(const boost::filesystem::path& file) : file(file), stream(NULL) { |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | FileReadBytestream::~FileReadBytestream() { | 22 | FileReadBytestream::~FileReadBytestream() { |
| 21 | if (stream) { | 23 | if (stream) { |
| 22 | stream->close(); | 24 | stream->close(); |
| 25 | delete stream; | ||
| 23 | stream = NULL; | 26 | stream = NULL; |
| 24 | } | 27 | } |
| 25 | } | 28 | } |
| 26 | 29 | ||
| 27 | boost::shared_ptr<ByteArray> FileReadBytestream::read(size_t size) { | 30 | boost::shared_ptr<ByteArray> FileReadBytestream::read(size_t size) { |
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,25 +1,27 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2013 Isode Limited. | 2 | * Copyright (c) 2010-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <boost/filesystem/fstream.hpp> | 7 | #include <Swiften/FileTransfer/FileWriteBytestream.h> |
| 8 | |||
| 8 | #include <cassert> | 9 | #include <cassert> |
| 9 | #include <boost/numeric/conversion/cast.hpp> | ||
| 10 | 10 | ||
| 11 | #include <Swiften/FileTransfer/FileWriteBytestream.h> | 11 | #include <boost/filesystem/fstream.hpp> |
| 12 | #include <boost/numeric/conversion/cast.hpp> | ||
| 12 | 13 | ||
| 13 | namespace Swift { | 14 | namespace Swift { |
| 14 | 15 | ||
| 15 | FileWriteBytestream::FileWriteBytestream(const boost::filesystem::path& file) : file(file), stream(NULL) { | 16 | FileWriteBytestream::FileWriteBytestream(const boost::filesystem::path& file) : file(file), stream(NULL) { |
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | FileWriteBytestream::~FileWriteBytestream() { | 19 | FileWriteBytestream::~FileWriteBytestream() { |
| 19 | if (stream) { | 20 | if (stream) { |
| 20 | stream->close(); | 21 | stream->close(); |
| 22 | delete stream; | ||
| 21 | stream = NULL; | 23 | stream = NULL; |
| 22 | } | 24 | } |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | void FileWriteBytestream::write(const std::vector<unsigned char>& data) { | 27 | void FileWriteBytestream::write(const std::vector<unsigned char>& data) { |
| @@ -35,10 +37,11 @@ void FileWriteBytestream::write(const std::vector<unsigned char>& data) { | |||
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | void FileWriteBytestream::close() { | 39 | void FileWriteBytestream::close() { |
| 38 | if (stream) { | 40 | if (stream) { |
| 39 | stream->close(); | 41 | stream->close(); |
| 42 | delete stream; | ||
| 40 | stream = NULL; | 43 | stream = NULL; |
| 41 | } | 44 | } |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | } | 47 | } |
Swift