@@ -64,6 +64,7 @@ class SecureContext : public BaseObject {
6464 static const int kMaxSessionSize = 10 * 1024 ;
6565
6666 protected:
67+ static const int64_t kExternalSize = sizeof (SSL_CTX);
6768
6869 static void New (const v8::FunctionCallbackInfo<v8::Value>& args);
6970 static void Init (const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -97,10 +98,12 @@ class SecureContext : public BaseObject {
9798 cert_(nullptr ),
9899 issuer_(nullptr ) {
99100 MakeWeak<SecureContext>(this );
101+ env->isolate ()->AdjustAmountOfExternalAllocatedMemory (kExternalSize );
100102 }
101103
102104 void FreeCTXMem () {
103105 if (ctx_) {
106+ env ()->isolate ()->AdjustAmountOfExternalAllocatedMemory (-kExternalSize );
104107 if (ctx_->cert_store == root_cert_store) {
105108 // SSL_CTX_free() will attempt to free the cert_store as well.
106109 // Since we want our root_cert_store to stay around forever
@@ -140,6 +143,7 @@ class SSLWrap {
140143 session_callbacks_(false ),
141144 new_session_wait_(false ) {
142145 ssl_ = SSL_new (sc->ctx_ );
146+ env_->isolate ()->AdjustAmountOfExternalAllocatedMemory (kExternalSize );
143147 CHECK_NE (ssl_, nullptr );
144148 }
145149
@@ -166,6 +170,12 @@ class SSLWrap {
166170 inline bool is_waiting_new_session () const { return new_session_wait_; }
167171
168172 protected:
173+ // Size allocated by OpenSSL: one for SSL structure, one for SSL3_STATE and
174+ // some for buffers.
175+ // NOTE: Actually it is much more than this
176+ static const int64_t kExternalSize =
177+ sizeof (SSL) + sizeof (SSL3_STATE) + 42 * 1024 ;
178+
169179 static void InitNPN (SecureContext* sc);
170180 static void AddMethods (Environment* env, v8::Handle<v8::FunctionTemplate> t);
171181
0 commit comments