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(); }