Skip to content

Commit 3f45cc1

Browse files
AdamMajerFishrock123
authored andcommitted
crypto: Use reference count to manage cert_store
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 <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent 8a9c45a commit 3f45cc1

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
773773
}
774774

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

src/node_crypto.h

-7
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ class SecureContext : public BaseObject {
142142
void FreeCTXMem() {
143143
if (ctx_) {
144144
env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
145-
if (ctx_->cert_store == root_cert_store) {
146-
// SSL_CTX_free() will attempt to free the cert_store as well.
147-
// Since we want our root_cert_store to stay around forever
148-
// we just clear the field. Hopefully OpenSSL will not modify this
149-
// struct in future versions.
150-
ctx_->cert_store = nullptr;
151-
}
152145
SSL_CTX_free(ctx_);
153146
if (cert_ != nullptr)
154147
X509_free(cert_);

0 commit comments

Comments
 (0)