-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zlib: fix memory leak for invalid input
Don’t toggle the weak/strong reference flag from the error handler, that’s too confusing. Instead, always do it in the code that handles the write call. Fixes: #22705 PR-URL: #22713 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
2 changed files
with
30 additions
and
4 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,28 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
const onGC = require('../common/ongc'); | ||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
// Checks that, if a zlib context fails with an error, it can still be GC'ed: | ||
// Refs: https://github.com/nodejs/node/issues/22705 | ||
|
||
const ongc = common.mustCall(); | ||
|
||
{ | ||
const input = Buffer.from('foobar'); | ||
const strm = zlib.createInflate(); | ||
strm.end(input); | ||
strm.once('error', common.mustCall((err) => { | ||
assert(err); | ||
setImmediate(() => { | ||
global.gc(); | ||
// Keep the event loop alive for seeing the async_hooks destroy hook | ||
// we use for GC tracking... | ||
// TODO(addaleax): This should maybe not be necessary? | ||
setImmediate(() => {}); | ||
}); | ||
})); | ||
onGC(strm, { ongc }); | ||
} |