From 7d66752f1f2de8173c0804af6ef4f32fcff8462b Mon Sep 17 00:00:00 2001 From: Matt Lavin Date: Tue, 24 May 2016 11:27:00 -0400 Subject: [PATCH] zlib: release callback and buffer after processing PR-URL: https://github.com/nodejs/node/pull/6955 Reviewed-By: Anna Henningsen Reviewed-By: Yuval Brik --- lib/zlib.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/zlib.js b/lib/zlib.js index 6715ff11604920..ecddfda653f7cb 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -560,6 +560,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) { + this.buffer = null; + this.callback = null; + } + if (self._hadError) return;