From 9ab8f9ddb75557bddcb1a391580a49918258421e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sat, 2 May 2015 00:59:05 +0300 Subject: [PATCH] tls_wrap: Unlink TLSWrap and SecureContext objects This makes `TLSWrap` and `SecureContext` objects collectable by the incremental gc. `res = null` destroys the cyclic reference in the `reading` property. `this.ssl = null` removes the remaining reference to the `TLSWrap`. `this.ssl._secureContext.context = null` removes the reference to the `SecureContext` object, even though there might be references to `this.ssl._secureContext` somewhere. The `reading` property will now throw an error if accessed after the socket is closed, but that should not happen. --- lib/_tls_wrap.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 95df8f56604682..0a30cd3310c1f1 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -289,15 +289,22 @@ TLSSocket.prototype._wrapHandle = function(handle) { } }); - this.on('close', this._destroySSL); + this.on('close', function() { + this._destroySSL(); + res = null; + }); return res; }; TLSSocket.prototype._destroySSL = function _destroySSL() { + if (!this.ssl) return; this.ssl.destroySSL(); - if (this.ssl._secureContext.singleUse) + if (this.ssl._secureContext.singleUse) { this.ssl._secureContext.context.close(); + this.ssl._secureContext.context = null; + } + this.ssl = null; }; TLSSocket.prototype._init = function(socket, wrap) {