Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

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 <[email protected]> PR-URL: nodejs/node-v0.x-archive#8687 Cherry-picked-from: nodejs/node-v0.x-archive@8c86898
1 parent 4481cf7 commit 0d02515

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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)