Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b07cb48

Browse filesBrowse files
mafintoshtargos
authored andcommitted
zlib: do not leak on destroy
PR-URL: #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>
1 parent dfecf85 commit b07cb48
Copy full SHA for b07cb48

File tree

Expand file treeCollapse file tree

3 files changed

+32
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+32
-0
lines changed
Open diff view settings
Collapse file

‎lib/zlib.js‎

Copy file name to clipboardExpand all lines: lib/zlib.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ Zlib.prototype.close = function close(callback) {
430430
this.destroy();
431431
};
432432

433+
Zlib.prototype._destroy = function _destroy(err, callback) {
434+
_close(this);
435+
callback(err);
436+
};
437+
433438
Zlib.prototype._transform = function _transform(chunk, encoding, cb) {
434439
var flushFlag = this._defaultFlushFlag;
435440
// We use a 'fake' zero-length chunk to carry information about flushes from
@@ -592,6 +597,10 @@ function processCallback() {
592597
assert(false, 'have should not go down');
593598
}
594599

600+
if (self.destroyed) {
601+
return;
602+
}
603+
595604
// exhausted the output buffer, or used all the input create a new one.
596605
if (availOutAfter === 0 || self._outOffset >= self._chunkSize) {
597606
handle.availOutBefore = self._chunkSize;
Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const zlib = require('zlib');
5+
6+
const ts = zlib.createGzip();
7+
const buf = Buffer.alloc(1024 * 1024 * 20);
8+
9+
ts.on('data', common.mustCall(() => ts.close()));
10+
ts.end(buf);
Collapse file

‎test/parallel/test-zlib-destroy.js‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const zlib = require('zlib');
7+
8+
// verify that the zlib transform does clean up
9+
// the handle when calling destroy.
10+
11+
const ts = zlib.createGzip();
12+
ts.destroy();
13+
assert.strictEqual(ts._handle, null);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.