diff options
author | Rich Trott <rtrott@gmail.com> | 2016-03-14 17:11:07 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-03-19 13:38:26 -0700 |
commit | 8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60 (patch) | |
tree | a2eed7fba6188d1d8fc2d7d08587039dc193e8d4 /lib/zlib.js | |
parent | a53b2ac4b1dcde5579d9cba814ca0c4b78e59a9f (diff) | |
download | android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.tar.gz android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.tar.bz2 android-node-v8-8b43d3f52dc4a2fc6e72ee21ba97111fa7447b60.zip |
zlib: do not emit event on *Sync() methods
Asynchronous functions in `zlib` should not emit the close event.
This fixes an issue where asynchronous calls in a for loop could exhaust
memory because the pending event prevents the objects from being garbage
collected.
Fixes: https://github.com/nodejs/node/issues/1668
PR-URL: https://github.com/nodejs/node/pull/5707
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Diffstat (limited to 'lib/zlib.js')
-rw-r--r-- | lib/zlib.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/zlib.js b/lib/zlib.js index 0028c35d79..79c78ea4a5 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -454,18 +454,21 @@ Zlib.prototype.flush = function(kind, callback) { }; Zlib.prototype.close = function(callback) { + _close(this, callback); + process.nextTick(emitCloseNT, this); +}; + +function _close(engine, callback) { if (callback) process.nextTick(callback); - if (this._closed) + if (engine._closed) return; - this._closed = true; + engine._closed = true; - this._handle.close(); - - process.nextTick(emitCloseNT, this); -}; + engine._handle.close(); +} function emitCloseNT(self) { self.emit('close'); @@ -535,12 +538,12 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) { } if (nread >= kMaxLength) { - this.close(); + _close(this); throw new RangeError(kRangeErrorMessage); } var buf = Buffer.concat(buffers, nread); - this.close(); + _close(this); return buf; } |