Skip to content

Commit 1543c78

Browse files
CraigCavMyles Borins
authored and
Myles Borins
committed
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: #3534 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d1cedbd commit 1543c78

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/zlib.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,9 @@ Zlib.prototype.flush = function(kind, callback) {
444444
if (callback)
445445
this.once('end', callback);
446446
} else if (ws.needDrain) {
447-
var self = this;
448-
this.once('drain', function() {
449-
self.flush(kind, callback);
450-
});
447+
if (callback) {
448+
this.once('drain', () => this.flush(kind, callback));
449+
}
451450
} else {
452451
this._flushFlag = kind;
453452
this.write(new Buffer(0), '', callback);

0 commit comments

Comments
 (0)