diff options
| author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-10-05 19:48:33 +0200 |
|---|---|---|
| committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-10-08 08:20:43 -0700 |
| commit | 406846fcc5193b587d724e0d9a516b581458d499 (patch) | |
| tree | 39a50270432863d11fecda4dfa316404da0586b0 /src/node_zlib.cc | |
| parent | 711ec07d3402c3494243afe191d6ecd13580fead (diff) | |
| download | node-406846fcc5193b587d724e0d9a516b581458d499.tar.gz | |
zlib: fix write request reference counting
Keep track of the reference count, don't make the wrapper object weak
when there are pending write requests. Fixes a regression from c79d516.
Diffstat (limited to 'src/node_zlib.cc')
| -rw-r--r-- | src/node_zlib.cc | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc index de5f1d5c9..2d411ab29 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -84,7 +84,8 @@ class ZCtx : public WeakObject { , mode_(mode) , strategy_(0) , windowBits_(0) - , write_in_progress_(false) { + , write_in_progress_(false) + , refs_(0) { } @@ -137,7 +138,7 @@ class ZCtx : public WeakObject { assert(!ctx->write_in_progress_ && "write already in progress"); ctx->write_in_progress_ = true; - ctx->ClearWeak(); + ctx->Ref(); assert(!args[0]->IsUndefined() && "must provide flush value"); @@ -291,7 +292,7 @@ class ZCtx : public WeakObject { Local<Value> args[2] = { avail_in, avail_out }; MakeCallback(env, handle, env->callback_string(), ARRAY_SIZE(args), args); - ctx->MakeWeak(); + ctx->Unref(); } static void Error(ZCtx* ctx, const char* message) { @@ -314,7 +315,7 @@ class ZCtx : public WeakObject { // no hope of rescue. ctx->write_in_progress_ = false; - ctx->MakeWeak(); + ctx->Unref(); } static void New(const FunctionCallbackInfo<Value>& args) { @@ -517,6 +518,19 @@ class ZCtx : public WeakObject { } private: + void Ref() { + if (++refs_ == 1) { + ClearWeak(); + } + } + + void Unref() { + assert(refs_ > 0); + if (--refs_ == 0) { + MakeWeak(); + } + } + static const int kDeflateContextSize = 16384; // approximate static const int kInflateContextSize = 10240; // approximate @@ -535,6 +549,7 @@ class ZCtx : public WeakObject { int windowBits_; uv_work_t work_req_; bool write_in_progress_; + unsigned int refs_; }; |
