diff --git a/lib/zlib.js b/lib/zlib.js index 079c413e2f9e7e..6d77f0240eaab0 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -373,9 +373,19 @@ function Zlib(opts, mode) { var strategy = exports.Z_DEFAULT_STRATEGY; if (typeof opts.strategy === 'number') strategy = opts.strategy; - this._handle.init(opts.windowBits || exports.Z_DEFAULT_WINDOWBITS, + var windowBits = exports.Z_DEFAULT_WINDOWBITS; + if (opts.windowBits && typeof opts.windowBits === 'number') { + windowBits = opts.windowBits; + } + + var memLevel = exports.Z_DEFAULT_MEMLEVEL; + if (opts.memLevel && typeof opts.memLevel === 'number') { + memLevel = opts.memLevel; + } + + this._handle.init(windowBits, level, - opts.memLevel || exports.Z_DEFAULT_MEMLEVEL, + memLevel, strategy, opts.dictionary); diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 304fbf72fed44f..66a6a476a7c7b2 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -469,16 +469,19 @@ class ZCtx : public AsyncWrap { CHECK(0 && "wtf?"); } - if (ctx->err_ != Z_OK) { - ZCtx::Error(ctx, "Init error"); - } - - ctx->dictionary_ = reinterpret_cast(dictionary); ctx->dictionary_len_ = dictionary_len; ctx->write_in_progress_ = false; ctx->init_done_ = true; + + if (ctx->err_ != Z_OK) { + if (dictionary != nullptr) { + delete[] dictionary; + ctx->dictionary_ = nullptr; + } + ctx->env()->ThrowError("Init error"); + } } static void SetDictionary(ZCtx* ctx) {