Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tls_wrap: hold secureContext ref in JS-land
Ensure no persistent-induced loops in C++-land by storing
`SecureContext` reference in JS-land.
  • Loading branch information
indutny committed Mar 6, 2015
commit 2879b03afc23532a8d6420f5e16ee8205a2a141b
1 change: 1 addition & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 4 additions & 6 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ using v8::Value;
TLSWrap::TLSWrap(Environment* env,
Kind kind,
StreamBase* stream,
Handle<Object> sc)
: SSLWrap<TLSWrap>(env, Unwrap<SecureContext>(sc), kind),
SecureContext* sc)
: SSLWrap<TLSWrap>(env, sc, kind),
StreamBase(env),
AsyncWrap(env,
env->tls_wrap_constructor_function()->NewInstance(),
AsyncWrap::PROVIDER_TLSWRAP),
sc_(Unwrap<SecureContext>(sc)),
sc_handle_(env->isolate(), sc),
sc_(sc),
stream_(stream),
enc_in_(nullptr),
enc_out_(nullptr),
Expand Down Expand Up @@ -82,7 +81,6 @@ TLSWrap::~TLSWrap() {
clear_in_ = nullptr;

sc_ = nullptr;
sc_handle_.Reset();

#ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
sni_context_.Reset();
Expand Down Expand Up @@ -192,7 +190,7 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& args) {
});
CHECK_NE(stream, nullptr);

TLSWrap* res = new TLSWrap(env, kind, stream, sc);
TLSWrap* res = new TLSWrap(env, kind, stream, Unwrap<SecureContext>(sc));

args.GetReturnValue().Set(res->object());
}
Expand Down
3 changes: 1 addition & 2 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TLSWrap : public crypto::SSLWrap<TLSWrap>,
TLSWrap(Environment* env,
Kind kind,
StreamBase* stream,
v8::Handle<v8::Object> sc);
crypto::SecureContext* sc);

static void SSLInfoCallback(const SSL* ssl_, int where, int ret);
void InitSSL();
Expand Down Expand Up @@ -140,7 +140,6 @@ class TLSWrap : public crypto::SSLWrap<TLSWrap>,
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB

crypto::SecureContext* sc_;
v8::Persistent<v8::Object> sc_handle_;
StreamBase* stream_;
BIO* enc_in_;
BIO* enc_out_;
Expand Down