Skip to content

Fix memory leak on http binary send #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions include/pion/http/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<const char *, size_t> > {
class binary_cache_t : public std::vector<std::pair<std::unique_ptr<const char>, 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<const char>{data_ptr}, size ) );
return boost::asio::buffer(data_ptr, size);
}
};
Expand Down