Skip to content

Commit 686344a

Browse files
fix: unique_ptr on g++-8 needs to know sizeof() z_stream up front, so we must use a raw ptr :(
1 parent adb25d1 commit 686344a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

include/dpp/zlibcontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class zlibcontext {
4848
* @brief Zlib stream struct. The actual type is defined in zlib.h
4949
* so is only defined in the implementation file.
5050
*/
51-
std::unique_ptr<z_stream> d_stream{};
51+
z_stream* d_stream{};
5252

5353
/**
5454
* @brief ZLib decompression buffer.

src/dpp/zlibcontext.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@
2626
namespace dpp {
2727

2828
zlibcontext::zlibcontext() {
29-
d_stream = std::make_unique<z_stream>();
30-
std::memset(d_stream.get(), 0, sizeof(z_stream));
31-
int error = inflateInit(d_stream.get());
29+
d_stream = new z_stream();
30+
std::memset(d_stream, 0, sizeof(z_stream));
31+
int error = inflateInit(d_stream);
3232
if (error != Z_OK) {
33+
delete d_stream;
3334
throw dpp::connection_exception((exception_error_code)error, "Can't initialise stream compression!");
3435
}
3536
decomp_buffer.resize(DECOMP_BUFFER_SIZE);
3637
}
3738

3839
zlibcontext::~zlibcontext() {
39-
inflateEnd(d_stream.get());
40+
inflateEnd(d_stream);
41+
delete d_stream;
4042
}
4143

4244
exception_error_code zlibcontext::decompress(const std::string& buffer, std::string& decompressed) {
@@ -47,7 +49,7 @@ exception_error_code zlibcontext::decompress(const std::string& buffer, std::str
4749
do {
4850
d_stream->next_out = static_cast<Bytef*>(decomp_buffer.data());
4951
d_stream->avail_out = DECOMP_BUFFER_SIZE;
50-
int ret = inflate(d_stream.get(), Z_NO_FLUSH);
52+
int ret = inflate(d_stream, Z_NO_FLUSH);
5153
size_t have = DECOMP_BUFFER_SIZE - d_stream->avail_out;
5254
switch (ret)
5355
{

0 commit comments

Comments
 (0)