diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index 6e726f556d..11ceb3fa84 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -69,34 +69,4 @@ T* grow(std::vector& vec, std::size_t num) return vec.data() + pos; } -/** - * Simple vector template class, with automatic free. - * - * @note There are no asserts in the class so you have - * to care about that you grab an item which is - * inside the list. - * - * @param T The type of the items stored, must be a pointer - */ -template -class AutoFreeSmallVector : public std::vector { -public: - ~AutoFreeSmallVector() - { - this->Clear(); - } - - /** - * Remove all items from the list. - */ - inline void Clear() - { - for (T p : *this) { - free(p); - } - - std::vector::clear(); - } -}; - #endif /* SMALLVEC_TYPE_HPP */ diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 8c68b98f87..4dc5a80415 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -42,7 +42,7 @@ struct PacketReader : LoadFilter { static const size_t CHUNK = 32 * 1024; ///< 32 KiB chunks of memory. - AutoFreeSmallVector blocks; ///< Buffer with blocks of allocated memory. + std::vector blocks; ///< Buffer with blocks of allocated memory. byte *buf; ///< Buffer we're going to write to/read from. byte *bufe; ///< End of the buffer we write to/read from. byte **block; ///< The block we're reading from/writing to. @@ -54,6 +54,13 @@ struct PacketReader : LoadFilter { { } + ~PacketReader() override + { + for (auto p : this->blocks) { + free(p); + } + } + /** * Add a packet to this buffer. * @param p The packet to add. diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 721631fe68..f03e3d659f 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -126,15 +126,22 @@ struct ReadBuffer { /** Container for dumping the savegame (quickly) to memory. */ struct MemoryDumper { - AutoFreeSmallVector blocks; ///< Buffer with blocks of allocated memory. - byte *buf; ///< Buffer we're going to write to. - byte *bufe; ///< End of the buffer we write to. + std::vector blocks; ///< Buffer with blocks of allocated memory. + byte *buf; ///< Buffer we're going to write to. + byte *bufe; ///< End of the buffer we write to. /** Initialise our variables. */ MemoryDumper() : buf(NULL), bufe(NULL) { } + ~MemoryDumper() + { + for (auto p : this->blocks) { + free(p); + } + } + /** * Write a single byte into the dumper. * @param b The byte to write.