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 c6a43fa

Browse filesBrowse files
mafintoshMylesBorins
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 4749640 commit c6a43fa
Copy full SHA for c6a43fa

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
@@ -427,6 +427,11 @@ Zlib.prototype.close = function close(callback) {
427427
this.destroy();
428428
};
429429

430+
Zlib.prototype._destroy = function _destroy(err, callback) {
431+
_close(this);
432+
callback(err);
433+
};
434+
430435
Zlib.prototype._transform = function _transform(chunk, encoding, cb) {
431436
var flushFlag = this._defaultFlushFlag;
432437
// We use a 'fake' zero-length chunk to carry information about flushes from
@@ -589,6 +594,10 @@ function processCallback() {
589594
assert(false, 'have should not go down');
590595
}
591596

597+
if (self.destroyed) {
598+
return;
599+
}
600+
592601
// exhausted the output buffer, or used all the input create a new one.
593602
if (availOutAfter === 0 || self._outOffset >= self._chunkSize) {
594603
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.