Skip to content

Commit

Permalink
tls_wrap: Unlink TLSWrap and SecureContext objects
Browse files Browse the repository at this point in the history
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: #1580
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Shigeki Ohtsu <[email protected]>
  • Loading branch information
ChALkeR authored and indutny committed May 4, 2015
1 parent dacc1fa commit f7620fb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f7620fb

Please sign in to comment.