From 8c868989be778246bc4b9558f087d0f93724b83d Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 6 Nov 2014 22:03:08 +0300 Subject: [PATCH] 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 PR-URL: https://github.com/joyent/node/pull/8687 --- src/node_zlib.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 5c8578d86e8..e87a704ce58 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -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(); }