summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Buus <mathiasbuus@gmail.com>2018-10-18 17:40:57 +0200
committerMathias Buus <mathiasbuus@gmail.com>2018-10-23 17:59:17 +0200
commit8a02d941b6c2e053376dd70dd0cca2351903c577 (patch)
tree38923b8c6203139eb5fa498f9bcc2537f17bc0a4
parentd1d5924f1a360f18a6eda06655f7e821335e1eb6 (diff)
downloadandroid-node-v8-8a02d941b6c2e053376dd70dd0cca2351903c577.tar.gz
android-node-v8-8a02d941b6c2e053376dd70dd0cca2351903c577.tar.bz2
android-node-v8-8a02d941b6c2e053376dd70dd0cca2351903c577.zip
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>
-rw-r--r--lib/zlib.js9
-rw-r--r--test/parallel/test-zlib-close-in-ondata.js10
-rw-r--r--test/parallel/test-zlib-destroy.js13
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/zlib.js b/lib/zlib.js
index 61f57429d6..c833afff14 100644
--- a/lib/zlib.js
+++ b/lib/zlib.js
@@ -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;
diff --git a/test/parallel/test-zlib-close-in-ondata.js b/test/parallel/test-zlib-close-in-ondata.js
new file mode 100644
index 0000000000..44d996311d
--- /dev/null
+++ b/test/parallel/test-zlib-close-in-ondata.js
@@ -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);
diff --git a/test/parallel/test-zlib-destroy.js b/test/parallel/test-zlib-destroy.js
new file mode 100644
index 0000000000..d8eab42186
--- /dev/null
+++ b/test/parallel/test-zlib-destroy.js
@@ -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);