-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #1668 PR-URL: #5707 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: trevnorris - Trevor Norris <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
- Loading branch information
Showing
2 changed files
with
32 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
require('../common'); | ||
const zlib = require('zlib'); | ||
const assert = require('assert'); | ||
|
||
const shouldNotBeCalled = () => { throw new Error('unexpected event'); }; | ||
|
||
const message = 'Come on, Fhqwhgads.'; | ||
|
||
const zipper = new zlib.Gzip(); | ||
zipper.on('close', shouldNotBeCalled); | ||
|
||
const buffer = new Buffer(message); | ||
const zipped = zipper._processChunk(buffer, zlib.Z_FINISH); | ||
|
||
const unzipper = new zlib.Gunzip(); | ||
unzipper.on('close', shouldNotBeCalled); | ||
|
||
const unzipped = unzipper._processChunk(zipped, zlib.Z_FINISH); | ||
assert.notEqual(zipped.toString(), message); | ||
assert.strictEqual(unzipped.toString(), message); |