Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release zlib callbacks and buffer after processing chunks #6955

Closed
Closed
Changes from all commits
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
10 changes: 10 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,16 @@ Zlib.prototype._processChunk = function(chunk, flushFlag, cb) {
req.callback = callback;

function callback(availInAfter, availOutAfter) {
// When the callback is used in an async write, the callback's
// context is the `req` object that was created. The req object
// is === this._handle, and that's why it's important to null
// out the values after they are done being used. `this._handle`
// can stay in memory longer than the callback and buffer are needed.
if (this) {
Copy link
Member

@addaleax addaleax May 24, 2016

Choose a reason for hiding this comment

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

I’d like it if there was a comment here saying that this === req (=== self._handle)

Copy link
Contributor

@ronkorving ronkorving May 25, 2016

Choose a reason for hiding this comment

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

Will this ever be falsy or not req?

Copy link
Member

Choose a reason for hiding this comment

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

no and no, I think… I guess just asking to change the variable instead of asking for the above comment woud have been easier, sorry

Copy link
Contributor Author

@mdlavin mdlavin May 25, 2016

Choose a reason for hiding this comment

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

this will be falsy when callback is called from line 547. And, this will equal newReq (not req) when callback is called from the async write on line 623.

Well, I guess req and newReq are technically the same value with the current implementation. But this can definitely be falsy

Copy link
Member

Choose a reason for hiding this comment

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

@mdlavin newReq === req because _handle.write() just returns _handle (I know it’s confusing)… but yes you can leave it like this then.

this.buffer = null;
this.callback = null;
}

if (self._hadError)
return;

Expand Down