zlib: do not leak on destroy
PR-URL: https://github.com/nodejs/node/pull/23734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
d1d5924f1a
commit
8a02d941b6
@ -430,6 +430,11 @@ Zlib.prototype.close = function close(callback) {
|
||||
this.destroy();
|
||||
};
|
||||
|
||||
Zlib.prototype._destroy = function _destroy(err, callback) {
|
||||
_close(this);
|
||||
callback(err);
|
||||
};
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
10
test/parallel/test-zlib-close-in-ondata.js
Normal file
10
test/parallel/test-zlib-close-in-ondata.js
Normal file
@ -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);
|
13
test/parallel/test-zlib-destroy.js
Normal file
13
test/parallel/test-zlib-destroy.js
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user