Skip to content

Commit f214b9a

Browse files
committed
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.
1 parent dacc1fa commit f214b9a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/_tls_wrap.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,22 @@ TLSSocket.prototype._wrapHandle = function(handle) {
289289
}
290290
});
291291

292-
this.on('close', this._destroySSL);
292+
this.on('close', function() {
293+
this._destroySSL();
294+
res = null;
295+
});
293296

294297
return res;
295298
};
296299

297300
TLSSocket.prototype._destroySSL = function _destroySSL() {
301+
if (!this.ssl) return;
298302
this.ssl.destroySSL();
299-
if (this.ssl._secureContext.singleUse)
303+
if (this.ssl._secureContext.singleUse) {
300304
this.ssl._secureContext.context.close();
305+
this.ssl._secureContext.context = null;
306+
}
307+
this.ssl = null;
301308
};
302309

303310
TLSSocket.prototype._init = function(socket, wrap) {

0 commit comments

Comments
 (0)