Skip to content

Commit 0d02515

Browse files
indutnypiscisaureus
authored andcommitted
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: nodejs/node-v0.x-archive#8687 Cherry-picked-from: nodejs/node-v0.x-archive@8c86898
1 parent 4481cf7 commit 0d02515

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/node_zlib.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ class ZCtx : public AsyncWrap {
358358
ctx->MakeCallback(env->onerror_string(), ARRAY_SIZE(args), args);
359359

360360
// no hope of rescue.
361+
if (ctx->write_in_progress_)
362+
ctx->Unref();
361363
ctx->write_in_progress_ = false;
362-
ctx->Unref();
363364
if (ctx->pending_close_)
364365
ctx->Close();
365366
}

0 commit comments

Comments
 (0)