From a70dc07f466194f24f0a92fa006f57381a26e1ef Mon Sep 17 00:00:00 2001 From: klaus triendl Date: Wed, 2 Sep 2020 21:09:14 +0200 Subject: [PATCH] Fix memory leak in http writer's binary data cache (issue #11) --- include/pion/http/writer.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/pion/http/writer.hpp b/include/pion/http/writer.hpp index e245ff3de..55c68a2c5 100644 --- a/include/pion/http/writer.hpp +++ b/include/pion/http/writer.hpp @@ -305,13 +305,19 @@ 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 : protected std::vector > { public: ~binary_cache_t() { for (iterator i=begin(); i!=end(); ++i) { delete[] i->first; } } + void clear() { + for (iterator i = begin(); i != end(); ++i) { + delete[] i->first; + } + std::vector >::clear(); + } inline boost::asio::const_buffer add(const void *ptr, const size_t size) { char *data_ptr = new char[size]; memcpy(data_ptr, ptr, size);