summaryrefslogtreecommitdiff
path: root/src/node_zlib.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-09-05 17:52:21 +0200
committerAnna Henningsen <anna@addaleax.net>2018-09-06 10:54:37 +0200
commit0c30d0e4e02e5b2b125a4eccb29ae8f48b457b8a (patch)
tree8d9f82fc88a1619945cc72c344ee782be38d577a /src/node_zlib.cc
parent2bf4697ff4be6a510410be1f1e67549be347614b (diff)
downloadandroid-node-v8-0c30d0e4e02e5b2b125a4eccb29ae8f48b457b8a.tar.gz
android-node-v8-0c30d0e4e02e5b2b125a4eccb29ae8f48b457b8a.tar.bz2
android-node-v8-0c30d0e4e02e5b2b125a4eccb29ae8f48b457b8a.zip
zlib: fix memory leak for invalid input
Don’t toggle the weak/strong reference flag from the error handler, that’s too confusing. Instead, always do it in the code that handles the write call. Fixes: https://github.com/nodejs/node/issues/22705 PR-URL: https://github.com/nodejs/node/pull/22713 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_zlib.cc')
-rw-r--r--src/node_zlib.cc6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index cd15603f0b..3d7c6b0047 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -215,8 +215,8 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
ctx->write_result_[0] = ctx->strm_.avail_out;
ctx->write_result_[1] = ctx->strm_.avail_in;
ctx->write_in_progress_ = false;
- ctx->Unref();
}
+ ctx->Unref();
return;
}
@@ -364,6 +364,7 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
// v8 land!
void AfterThreadPoolWork(int status) override {
AllocScope alloc_scope(this);
+ OnScopeLeave on_scope_leave([&]() { Unref(); });
write_in_progress_ = false;
@@ -388,7 +389,6 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
write_js_callback_);
MakeCallback(cb, 0, nullptr);
- Unref();
if (pending_close_)
Close();
}
@@ -410,8 +410,6 @@ class ZCtx : public AsyncWrap, public ThreadPoolWork {
MakeCallback(env()->onerror_string(), arraysize(args), args);
// no hope of rescue.
- if (write_in_progress_)
- Unref();
write_in_progress_ = false;
if (pending_close_)
Close();