Skip to content

Commit 7d0e9a5

Browse files
committed
src: move BaseObject subclass dtors out of node_crypto.h
Move destructors for subclasses of `BaseObject` from node_crypto.h to node_crypto.cc. This removes the need to include base_object-inl.h when using node_crypto.h in some cases.
1 parent 51ccf1b commit 7d0e9a5

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/node_crypto.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
531531
env->set_secure_context_constructor_template(t);
532532
}
533533

534+
SecureContext::~SecureContext() {
535+
Reset();
536+
}
534537

535538
void SecureContext::New(const FunctionCallbackInfo<Value>& args) {
536539
Environment* env = Environment::GetCurrent(args);
@@ -4716,6 +4719,10 @@ void Hash::Initialize(Environment* env, Local<Object> target) {
47164719
t->GetFunction(env->context()).ToLocalChecked()).Check();
47174720
}
47184721

4722+
Hash::~Hash() {
4723+
if (md_value_ != nullptr)
4724+
OPENSSL_clear_free(md_value_, md_len_);
4725+
}
47194726

47204727
void Hash::New(const FunctionCallbackInfo<Value>& args) {
47214728
Environment* env = Environment::GetCurrent(args);
@@ -5956,6 +5963,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
59565963
t->GetFunction(env->context()).ToLocalChecked()).Check();
59575964
}
59585965

5966+
ECDH::~ECDH() {}
59595967

59605968
void ECDH::New(const FunctionCallbackInfo<Value>& args) {
59615969
Environment* env = Environment::GetCurrent(args);

src/node_crypto.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ extern void UseExtraCaCerts(const std::string& file);
8080

8181
void InitCryptoOnce();
8282

83-
class SecureContext : public BaseObject {
83+
class SecureContext final : public BaseObject {
8484
public:
85-
~SecureContext() override {
86-
Reset();
87-
}
85+
~SecureContext() override;
8886

8987
static void Initialize(Environment* env, v8::Local<v8::Object> target);
9088

@@ -588,8 +586,10 @@ class Hmac : public BaseObject {
588586
DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_;
589587
};
590588

591-
class Hash : public BaseObject {
589+
class Hash final : public BaseObject {
592590
public:
591+
~Hash() override;
592+
593593
static void Initialize(Environment* env, v8::Local<v8::Object> target);
594594

595595
// TODO(joyeecheung): track the memory used by OpenSSL types
@@ -613,11 +613,6 @@ class Hash : public BaseObject {
613613
MakeWeak();
614614
}
615615

616-
~Hash() override {
617-
if (md_value_ != nullptr)
618-
OPENSSL_clear_free(md_value_, md_len_);
619-
}
620-
621616
private:
622617
EVPMDPointer mdctx_;
623618
bool has_md_;
@@ -790,11 +785,9 @@ class DiffieHellman : public BaseObject {
790785
DHPointer dh_;
791786
};
792787

793-
class ECDH : public BaseObject {
788+
class ECDH final : public BaseObject {
794789
public:
795-
~ECDH() override {
796-
group_ = nullptr;
797-
}
790+
~ECDH() override;
798791

799792
static void Initialize(Environment* env, v8::Local<v8::Object> target);
800793
static ECPointPointer BufferToPoint(Environment* env,

0 commit comments

Comments
 (0)