Skip to content

Commit

Permalink
crypto: Use reference count to manage cert_store
Browse files Browse the repository at this point in the history
Setting reference count at the time of setting cert_store instead of
trying to manage it by modifying internal states in destructor.

PR-URL: #9409
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Shigeki Ohtsu <ohtsu@ohtsu.org>
  • Loading branch information
AdamMajer authored and MylesBorins committed Feb 1, 2017
1 parent d3a7fb8 commit bf882fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
}

sc->ca_store_ = root_cert_store;
// Increment reference count so global store is not deleted along with CTX.
CRYPTO_add(&root_cert_store->references, 1, CRYPTO_LOCK_X509_STORE);
SSL_CTX_set_cert_store(sc->ctx_, sc->ca_store_);
}

Expand Down
7 changes: 0 additions & 7 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@ class SecureContext : public BaseObject {
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
// we just clear the field. Hopefully OpenSSL will not modify this
// struct in future versions.
ctx_->cert_store = nullptr;
}
SSL_CTX_free(ctx_);
if (cert_ != nullptr)
X509_free(cert_);
Expand Down

0 comments on commit bf882fb

Please sign in to comment.