summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-08-04 21:51:29 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-08-04 21:51:29 +0200
commitca1fc859f27560c7988f078cff89f40f1b6e2c0f (patch)
treed55c07d430bfa7191288789bfb0beeee5f3a63d3
parentf979ba0e12a01749aa6683401a7543629c00a09e (diff)
Fixed memory leak caused by exceptions in HTTP::Connection::send_file().
-rw-r--r--http_connection.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/http_connection.cpp b/http_connection.cpp
index 61928d3..4411a92 100644
--- a/http_connection.cpp
+++ b/http_connection.cpp
@@ -7,6 +7,7 @@
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/scoped_array.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -104,10 +105,9 @@ void HTTP::Connection::send_file(const fs::path& filename) {
is.seekg(begin);
- char* buf = new char[end - begin];
- is.read(buf, end - begin);
- send_data(buf, is.gcount());
- delete buf;
+ boost::scoped_array<char> buf(new char[end-begin]);
+ is.read(buf.get(), end - begin);
+ send_data(buf.get(), is.gcount());
} else {
add_header("Content-Length", boost::str(boost::format("%d") % length));