diff options
author | Сковорода Никита Андреевич <chalkerx@gmail.com> | 2015-05-02 00:59:05 +0300 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2015-05-04 14:18:51 +0300 |
commit | f7620fb96d339f704932f9bb9a0dceb9952df2d4 (patch) | |
tree | ed2be55e579b4cb376d068e5dd70c842d6f15d59 | |
parent | dacc1fa35ce546e88e18bdc10d9bc584d098f713 (diff) | |
download | node-new-f7620fb96d339f704932f9bb9a0dceb9952df2d4.tar.gz |
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.
PR-URL: https://github.com/iojs/io.js/pull/1580
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
-rw-r--r-- | lib/_tls_wrap.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 95df8f5660..0a30cd3310 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) { |