From 2b20f641fc54a35a472d57dedcde722a2e5dc8d3 Mon Sep 17 00:00:00 2001 From: flatline Date: Mon, 21 May 2018 12:21:03 -0600 Subject: [PATCH] Fix ownership semantics for the http writer internal binary buffer. All sent memory was being leaked during binary sends. The old deletion scheme didn't work because the container size was already 0 by the time the destructor was hit and it was effectively a no-op. --- include/pion/http/writer.hpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/pion/http/writer.hpp b/include/pion/http/writer.hpp index e245ff3de..51366b318 100644 --- a/include/pion/http/writer.hpp +++ b/include/pion/http/writer.hpp @@ -305,17 +305,12 @@ class PION_API writer : /// used to cache binary data included within the payload content - class binary_cache_t : public std::vector > { + class binary_cache_t : public std::vector, size_t>> { public: - ~binary_cache_t() { - for (iterator i=begin(); i!=end(); ++i) { - delete[] i->first; - } - } inline boost::asio::const_buffer add(const void *ptr, const size_t size) { char *data_ptr = new char[size]; memcpy(data_ptr, ptr, size); - push_back( std::make_pair(data_ptr, size) ); + push_back(std::make_pair(std::unique_ptr{data_ptr}, size ) ); return boost::asio::buffer(data_ptr, size); } };