-
-
Notifications
You must be signed in to change notification settings - Fork 32k
zlib: do not leak on destroy #23734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zlib: do not leak on destroy #23734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,6 +430,11 @@ Zlib.prototype.close = function close(callback) { | |
this.destroy(); | ||
}; | ||
|
||
Zlib.prototype._destroy = function _destroy(err, callback) { | ||
_close(this); | ||
callback(err); | ||
}; | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Zlib.prototype._transform = function _transform(chunk, encoding, cb) { | ||
var flushFlag = this._defaultFlushFlag; | ||
// We use a 'fake' zero-length chunk to carry information about flushes from | ||
|
@@ -592,6 +597,10 @@ function processCallback() { | |
assert(false, 'have should not go down'); | ||
} | ||
|
||
if (self.destroyed) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a check for this a few line above, isn't that one sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the idea is that the Either way, it would be great to have a test for this (and the other bits in this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, makes sense, I think a comment would also help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually already tested as the existing tests fail (crash even!) without this. |
||
return; | ||
} | ||
|
||
// exhausted the output buffer, or used all the input create a new one. | ||
if (availOutAfter === 0 || self._outOffset >= self._chunkSize) { | ||
handle.availOutBefore = self._chunkSize; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const zlib = require('zlib'); | ||
|
||
const ts = zlib.createGzip(); | ||
const buf = Buffer.alloc(1024 * 1024 * 20); | ||
|
||
ts.on('data', common.mustCall(() => ts.close())); | ||
ts.end(buf); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const zlib = require('zlib'); | ||
|
||
// verify that the zlib transform does clean up | ||
// the handle when calling destroy. | ||
|
||
const ts = zlib.createGzip(); | ||
ts.destroy(); | ||
assert.strictEqual(ts._handle, null); |
Uh oh!
There was an error while loading. Please reload this page.