Skip to content

Commit c09c90c

Browse files
committed
tls_wrap: do not hold persistent ref to parent
Hold non-persistent reference in JS, rather than in C++ to avoid cycles. PR-URL: #1078 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent dccb69a commit c09c90c

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

lib/_tls_wrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ TLSSocket.prototype._wrapHandle = function(handle) {
286286
tls.createSecureContext();
287287
res = tls_wrap.wrap(handle, context.context, options.isServer);
288288
res._parent = handle;
289+
res._secureContext = context;
289290
res.reading = handle.reading;
290291
Object.defineProperty(handle, 'reading', {
291292
get: function readingGetter() {

src/tls_wrap.cc

+5-11
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ using v8::Value;
3737
TLSWrap::TLSWrap(Environment* env,
3838
Kind kind,
3939
StreamBase* stream,
40-
Handle<Object> stream_obj,
41-
Handle<Object> sc)
42-
: SSLWrap<TLSWrap>(env, Unwrap<SecureContext>(sc), kind),
40+
SecureContext* sc)
41+
: SSLWrap<TLSWrap>(env, sc, kind),
4342
StreamBase(env),
4443
AsyncWrap(env,
4544
env->tls_wrap_constructor_function()->NewInstance(),
4645
AsyncWrap::PROVIDER_TLSWRAP),
47-
sc_(Unwrap<SecureContext>(sc)),
48-
sc_handle_(env->isolate(), sc),
46+
sc_(sc),
4947
stream_(stream),
50-
stream_handle_(env->isolate(), stream_obj),
5148
enc_in_(nullptr),
5249
enc_out_(nullptr),
5350
clear_in_(nullptr),
@@ -84,9 +81,6 @@ TLSWrap::~TLSWrap() {
8481
clear_in_ = nullptr;
8582

8683
sc_ = nullptr;
87-
sc_handle_.Reset();
88-
stream_handle_.Reset();
89-
persistent().Reset();
9084

9185
#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
9286
sni_context_.Reset();
@@ -196,9 +190,9 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& args) {
196190
});
197191
CHECK_NE(stream, nullptr);
198192

199-
TLSWrap* res = new TLSWrap(env, kind, stream, stream_obj, sc);
193+
TLSWrap* res = new TLSWrap(env, kind, stream, Unwrap<SecureContext>(sc));
200194

201-
args.GetReturnValue().Set(res->persistent());
195+
args.GetReturnValue().Set(res->object());
202196
}
203197

204198

src/tls_wrap.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class TLSWrap : public crypto::SSLWrap<TLSWrap>,
7878
TLSWrap(Environment* env,
7979
Kind kind,
8080
StreamBase* stream,
81-
v8::Handle<v8::Object> stream_obj,
82-
v8::Handle<v8::Object> sc);
81+
crypto::SecureContext* sc);
8382

8483
static void SSLInfoCallback(const SSL* ssl_, int where, int ret);
8584
void InitSSL();
@@ -141,9 +140,7 @@ class TLSWrap : public crypto::SSLWrap<TLSWrap>,
141140
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
142141

143142
crypto::SecureContext* sc_;
144-
v8::Persistent<v8::Object> sc_handle_;
145143
StreamBase* stream_;
146-
v8::Persistent<v8::Object> stream_handle_;
147144
BIO* enc_in_;
148145
BIO* enc_out_;
149146
NodeBIO* clear_in_;

0 commit comments

Comments
 (0)