Skip to content

Commit

Permalink
zlib: only apply drain listener if given callback
Browse files Browse the repository at this point in the history
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: #3534
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
CraigCav authored and jasnell committed Dec 17, 2015
1 parent 4733a60 commit 47bb94a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 47bb94a

Please sign in to comment.