Commit 40d46a81 authored by Ingvar Stepanyan's avatar Ingvar Stepanyan

Fix double-free after move of context

parent e57066ca
......@@ -214,7 +214,7 @@ KJ_TEST("async gzip decompression") {
// Decompress using an output stream.
{
MockAsyncOutputStream rawOutput;
auto gzip = GzipAsyncOutputStream::Decompress(rawOutput);
GzipAsyncOutputStream gzip(rawOutput, GzipAsyncOutputStream::DECOMPRESS);
auto mid = sizeof(FOOBAR_GZIP) / 2;
gzip.write(FOOBAR_GZIP, mid).wait(io.waitScope);
......
......@@ -142,9 +142,12 @@ size_t GzipInputStream::readImpl(
// =======================================================================================
GzipOutputStream::GzipOutputStream(OutputStream& inner, kj::Maybe<int> compressionLevel)
GzipOutputStream::GzipOutputStream(OutputStream& inner, int compressionLevel)
: inner(inner), ctx(compressionLevel) {}
GzipOutputStream::GzipOutputStream(OutputStream& inner, decltype(DECOMPRESS))
: inner(inner), ctx(nullptr) {}
GzipOutputStream::~GzipOutputStream() noexcept(false) {
pump(Z_FINISH);
}
......@@ -228,9 +231,12 @@ Promise<size_t> GzipAsyncInputStream::readImpl(
// =======================================================================================
GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, kj::Maybe<int> compressionLevel)
GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, int compressionLevel)
: inner(inner), ctx(compressionLevel) {}
GzipAsyncOutputStream::GzipAsyncOutputStream(AsyncOutputStream& inner, decltype(DECOMPRESS))
: inner(inner), ctx(nullptr) {}
Promise<void> GzipAsyncOutputStream::write(const void* in, size_t size) {
ctx.setInput(in, size);
return pump(Z_NO_FLUSH);
......
......@@ -34,7 +34,6 @@ public:
GzipOutputContext(kj::Maybe<int> compressionLevel);
~GzipOutputContext() noexcept(false);
KJ_DISALLOW_COPY(GzipOutputContext);
GzipOutputContext(GzipOutputContext&&) = default;
void setInput(const void* in, size_t size);
kj::Tuple<bool, kj::ArrayPtr<const byte>> pumpOnce(int flush);
......@@ -69,14 +68,12 @@ private:
class GzipOutputStream final: public OutputStream {
public:
GzipOutputStream(OutputStream& inner, kj::Maybe<int> compressionLevel = Z_DEFAULT_COMPRESSION);
enum { DECOMPRESS };
GzipOutputStream(OutputStream& inner, int compressionLevel = Z_DEFAULT_COMPRESSION);
GzipOutputStream(OutputStream& inner, decltype(DECOMPRESS));
~GzipOutputStream() noexcept(false);
KJ_DISALLOW_COPY(GzipOutputStream);
GzipOutputStream(GzipOutputStream&&) = default;
static inline GzipOutputStream Decompress(OutputStream& inner) {
return GzipOutputStream(inner, nullptr);
}
void write(const void* buffer, size_t size) override;
using OutputStream::write;
......@@ -112,13 +109,11 @@ private:
class GzipAsyncOutputStream final: public AsyncOutputStream {
public:
GzipAsyncOutputStream(AsyncOutputStream& inner, kj::Maybe<int> compressionLevel = Z_DEFAULT_COMPRESSION);
KJ_DISALLOW_COPY(GzipAsyncOutputStream);
GzipAsyncOutputStream(GzipAsyncOutputStream&&) = default;
enum { DECOMPRESS };
static inline GzipAsyncOutputStream Decompress(AsyncOutputStream& inner) {
return GzipAsyncOutputStream(inner, nullptr);
}
GzipAsyncOutputStream(AsyncOutputStream& inner, int compressionLevel = Z_DEFAULT_COMPRESSION);
GzipAsyncOutputStream(AsyncOutputStream& inner, decltype(DECOMPRESS));
KJ_DISALLOW_COPY(GzipAsyncOutputStream);
Promise<void> write(const void* buffer, size_t size) override;
Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment