Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
zlib: do not leak on destroy
  • Loading branch information
mafintosh committed Oct 18, 2018
commit f1055e38aa5c6eb18150a031d58c92cb75dd67e3
9 changes: 9 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ Zlib.prototype.close = function close(callback) {
this.destroy();
};

Zlib.prototype._destroy = function _destroy(err, callback) {
_close(this);
callback(err);
Comment thread
mcollina marked this conversation as resolved.
};
Comment thread
addaleax marked this conversation as 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
Expand Down Expand Up @@ -592,6 +597,10 @@ function processCallback() {
assert(false, 'have should not go down');
}

if (self.destroyed) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the idea is that the push() call can trigger on('data') listeners which can destroy the stream?

Either way, it would be great to have a test for this (and the other bits in this PR)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense, I think a comment would also help.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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;
Expand Down