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
pull/23395/head
Fedor Indutny 2014-11-06 22:03:08 +03:00
parent f9456a2d36
commit 8c868989be
1 changed files with 2 additions and 1 deletions

View File

@ -307,8 +307,9 @@ class ZCtx : public ObjectWrap {
MakeCallback(ctx->handle_, onerror_sym, 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();
}