mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-17 22:56:18 +00:00
Release the zlib deflate state in gzip_compress_to_vector.
deflateEnd was never called, leaking 168 kB per compressed response.
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <torrent/exceptions.h>
|
#include <torrent/exceptions.h>
|
||||||
|
|
||||||
|
#include "utils/functional.h"
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -21,6 +23,8 @@ gzip_compress_to_vector(const char* buffer, unsigned int length, std::vector<cha
|
|||||||
if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits | gzip_encoding, gzip_level, Z_DEFAULT_STRATEGY) != Z_OK)
|
if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits | gzip_encoding, gzip_level, Z_DEFAULT_STRATEGY) != Z_OK)
|
||||||
throw torrent::internal_error("gzip_compress_to_vector(...) could not initialize gzip deflate.");
|
throw torrent::internal_error("gzip_compress_to_vector(...) could not initialize gzip deflate.");
|
||||||
|
|
||||||
|
scope_guard guard([&zs]() { deflateEnd(&zs); });
|
||||||
|
|
||||||
auto max_response_size = deflateBound(&zs, length);
|
auto max_response_size = deflateBound(&zs, length);
|
||||||
|
|
||||||
output.resize(offset + max_response_size);
|
output.resize(offset + max_response_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user