summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2014-02-13 17:17:59 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2014-02-18 01:11:05 +0400
commit829a9b8cba0680f1d451551e12491e7b0e1ea92f (patch)
tree2f03648b355b4167210bfaf253bfe0ecb006706c /src
parent86b8d84811484763b251b9a8a2b9e673964ea6b5 (diff)
downloadandroid-node-v8-829a9b8cba0680f1d451551e12491e7b0e1ea92f.tar.gz
android-node-v8-829a9b8cba0680f1d451551e12491e7b0e1ea92f.tar.bz2
android-node-v8-829a9b8cba0680f1d451551e12491e7b0e1ea92f.zip
zlib: introduce pending close state
zlib should not crash in `close()` if the write is still in progress. fix #7101
Diffstat (limited to 'src')
-rw-r--r--src/node_zlib.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index d522676284..5c8578d86e 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -72,18 +72,25 @@ class ZCtx : public ObjectWrap {
, flush_(0)
, chunk_size_(0)
, write_in_progress_(false)
+ , pending_close_(false)
, mode_(mode)
{
}
~ZCtx() {
+ assert(!write_in_progress_ && "write in progress");
Close();
}
void Close() {
- assert(!write_in_progress_ && "write in progress");
+ if (write_in_progress_) {
+ pending_close_ = true;
+ return;
+ }
+
+ pending_close_ = false;
assert(init_done_ && "close before init");
assert(mode_ <= UNZIP);
@@ -122,6 +129,7 @@ class ZCtx : public ObjectWrap {
assert(ctx->mode_ != NONE && "already finalized");
assert(!ctx->write_in_progress_ && "write already in progress");
+ assert(!ctx->pending_close_ && "close is pending");
ctx->write_in_progress_ = true;
ctx->Ref();
@@ -279,6 +287,8 @@ class ZCtx : public ObjectWrap {
MakeCallback(ctx->handle_, callback_sym, ARRAY_SIZE(args), args);
ctx->Unref();
+ if (ctx->pending_close_)
+ ctx->Close();
}
static void Error(ZCtx *ctx, const char *msg_) {
@@ -299,6 +309,8 @@ class ZCtx : public ObjectWrap {
// no hope of rescue.
ctx->write_in_progress_ = false;
ctx->Unref();
+ if (ctx->pending_close_)
+ ctx->Close();
}
static Handle<Value> New(const Arguments& args) {
@@ -495,6 +507,7 @@ class ZCtx : public ObjectWrap {
int chunk_size_;
bool write_in_progress_;
+ bool pending_close_;
uv_work_t work_req_;
node_zlib_mode mode_;