diff options
author | Craig Cavalier <craigcav@gmail.com> | 2015-10-26 14:40:56 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2015-11-14 08:11:28 -0800 |
commit | 1736ad82643c0b55027626f330dff9af1519f04b (patch) | |
tree | ae8c2feccefde9e959202898abffbcee6c04faa2 /lib/zlib.js | |
parent | fa27c5634b4e0bd1699eca526d415147fe334107 (diff) | |
download | android-node-v8-1736ad82643c0b55027626f330dff9af1519f04b.tar.gz android-node-v8-1736ad82643c0b55027626f330dff9af1519f04b.tar.bz2 android-node-v8-1736ad82643c0b55027626f330dff9af1519f04b.zip |
zlib: only apply drain listener if given callback
When stream.flush() is called without a callback, an empty listener is
being added. Since flush may be called multiple times to push SSE's
down to the client, multiple noop listeners are being added. This in
turn causes the memory leak detected message.
PR-URL: https://github.com/nodejs/node/pull/3534
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/zlib.js')
-rw-r--r-- | lib/zlib.js | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/zlib.js b/lib/zlib.js index 996d1116ee..3e6f7b1876 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -444,10 +444,9 @@ Zlib.prototype.flush = function(kind, callback) { if (callback) this.once('end', callback); } else if (ws.needDrain) { - var self = this; - this.once('drain', function() { - self.flush(kind, callback); - }); + if (callback) { + this.once('drain', () => this.flush(kind, callback)); + } } else { this._flushFlag = kind; this.write(new Buffer(0), '', callback); |