summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-04-26 14:27:46 +0200
committerFedor Indutny <fedor@indutny.com>2015-04-30 11:02:23 +0200
commite6874dd0f9c62a515b64ed35a4806f667152b6ec (patch)
tree96fb324b52d4057a7b39b44c471cf3e2dde82b9e /src
parent2d241b3b82d246881c8a6bcc7148d59349309d5f (diff)
downloadandroid-node-v8-e6874dd0f9c62a515b64ed35a4806f667152b6ec.tar.gz
android-node-v8-e6874dd0f9c62a515b64ed35a4806f667152b6ec.tar.bz2
android-node-v8-e6874dd0f9c62a515b64ed35a4806f667152b6ec.zip
crypto: track external memory for SSL structures
Ensure that GC kicks in at the right times and the RSS does not blow up. Fix: https://github.com/iojs/io.js/issues/1522 PR-URL: https://github.com/iojs/io.js/pull/1529 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc1
-rw-r--r--src/node_crypto.h10
2 files changed, 11 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 1a7388bea0..b980fb0ab6 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -1878,6 +1878,7 @@ void SSLWrap<Base>::DestroySSL() {
return;
SSL_free(ssl_);
+ env_->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
ssl_ = nullptr;
}
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 8fec4bb625..a623ccbf26 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -64,6 +64,7 @@ class SecureContext : public BaseObject {
static const int kMaxSessionSize = 10 * 1024;
protected:
+ static const int64_t kExternalSize = sizeof(SSL_CTX);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Init(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -97,10 +98,12 @@ class SecureContext : public BaseObject {
cert_(nullptr),
issuer_(nullptr) {
MakeWeak<SecureContext>(this);
+ env->isolate()->AdjustAmountOfExternalAllocatedMemory(kExternalSize);
}
void FreeCTXMem() {
if (ctx_) {
+ env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
if (ctx_->cert_store == root_cert_store) {
// SSL_CTX_free() will attempt to free the cert_store as well.
// Since we want our root_cert_store to stay around forever
@@ -140,6 +143,7 @@ class SSLWrap {
session_callbacks_(false),
new_session_wait_(false) {
ssl_ = SSL_new(sc->ctx_);
+ env_->isolate()->AdjustAmountOfExternalAllocatedMemory(kExternalSize);
CHECK_NE(ssl_, nullptr);
}
@@ -166,6 +170,12 @@ class SSLWrap {
inline bool is_waiting_new_session() const { return new_session_wait_; }
protected:
+ // Size allocated by OpenSSL: one for SSL structure, one for SSL3_STATE and
+ // some for buffers.
+ // NOTE: Actually it is much more than this
+ static const int64_t kExternalSize =
+ sizeof(SSL) + sizeof(SSL3_STATE) + 42 * 1024;
+
static void InitNPN(SecureContext* sc);
static void AddMethods(Environment* env, v8::Handle<v8::FunctionTemplate> t);