From 47bb94a0c33c7996b8dafe3f70a4e569f6717cbc Mon Sep 17 00:00:00 2001 From: Craig Cavalier Date: Mon, 26 Oct 2015 14:40:56 -0700 Subject: [PATCH] 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 Reviewed-By: James M Snell --- lib/zlib.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/zlib.js b/lib/zlib.js index 1151b2cb88c07b..82b08018e7403e 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);