From c09c90c1a9e74ee4f29a051daf10bc4c5d5f7755 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 5 Mar 2015 20:27:58 -0500 Subject: [PATCH] tls_wrap: do not hold persistent ref to parent Hold non-persistent reference in JS, rather than in C++ to avoid cycles. PR-URL: https://github.com/iojs/io.js/pull/1078 Reviewed-By: Ben Noordhuis --- lib/_tls_wrap.js | 1 + src/tls_wrap.cc | 16 +++++----------- src/tls_wrap.h | 5 +---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 0d1a2457283624..2fd13ef83db1c9 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -286,6 +286,7 @@ TLSSocket.prototype._wrapHandle = function(handle) { tls.createSecureContext(); res = tls_wrap.wrap(handle, context.context, options.isServer); res._parent = handle; + res._secureContext = context; res.reading = handle.reading; Object.defineProperty(handle, 'reading', { get: function readingGetter() { diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index b05b8891d0fdd5..a42e5faa70d8ae 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -37,17 +37,14 @@ using v8::Value; TLSWrap::TLSWrap(Environment* env, Kind kind, StreamBase* stream, - Handle stream_obj, - Handle sc) - : SSLWrap(env, Unwrap(sc), kind), + SecureContext* sc) + : SSLWrap(env, sc, kind), StreamBase(env), AsyncWrap(env, env->tls_wrap_constructor_function()->NewInstance(), AsyncWrap::PROVIDER_TLSWRAP), - sc_(Unwrap(sc)), - sc_handle_(env->isolate(), sc), + sc_(sc), stream_(stream), - stream_handle_(env->isolate(), stream_obj), enc_in_(nullptr), enc_out_(nullptr), clear_in_(nullptr), @@ -84,9 +81,6 @@ TLSWrap::~TLSWrap() { clear_in_ = nullptr; sc_ = nullptr; - sc_handle_.Reset(); - stream_handle_.Reset(); - persistent().Reset(); #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB sni_context_.Reset(); @@ -196,9 +190,9 @@ void TLSWrap::Wrap(const FunctionCallbackInfo& args) { }); CHECK_NE(stream, nullptr); - TLSWrap* res = new TLSWrap(env, kind, stream, stream_obj, sc); + TLSWrap* res = new TLSWrap(env, kind, stream, Unwrap(sc)); - args.GetReturnValue().Set(res->persistent()); + args.GetReturnValue().Set(res->object()); } diff --git a/src/tls_wrap.h b/src/tls_wrap.h index 73a9f84ec0d1b7..9f095355bb58bd 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -78,8 +78,7 @@ class TLSWrap : public crypto::SSLWrap, TLSWrap(Environment* env, Kind kind, StreamBase* stream, - v8::Handle stream_obj, - v8::Handle sc); + crypto::SecureContext* sc); static void SSLInfoCallback(const SSL* ssl_, int where, int ret); void InitSSL(); @@ -141,9 +140,7 @@ class TLSWrap : public crypto::SSLWrap, #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB crypto::SecureContext* sc_; - v8::Persistent sc_handle_; StreamBase* stream_; - v8::Persistent stream_handle_; BIO* enc_in_; BIO* enc_out_; NodeBIO* clear_in_;