Browse Source

zlib: do not unref() if wasn't ref()ed

In very unlikely case, where `deflateInit2()` may return error (right
now happening only on exhausting all memory), the `ZCtx::Error()` will
be called and will try to `Unref()` the handle. But the problem is that
this handle was never `Ref()`ed, so it will trigger an assertion error
and crash the program.

Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl>
PR-URL: https://github.com/joyent/node/pull/8687

Cherry-picked-from: 8c868989be
v1.8.0-commit
Fedor Indutny 10 years ago
committed by Bert Belder
parent
commit
0d02515d6e
  1. 3
      src/node_zlib.cc

3
src/node_zlib.cc

@ -358,8 +358,9 @@ class ZCtx : public AsyncWrap {
ctx->MakeCallback(env->onerror_string(), ARRAY_SIZE(args), args);
// no hope of rescue.
if (ctx->write_in_progress_)
ctx->Unref();
ctx->write_in_progress_ = false;
ctx->Unref();
if (ctx->pending_close_)
ctx->Close();
}

Loading…
Cancel
Save