diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 3bf480f8f0c77d..97777371265510 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -992,18 +992,17 @@ static MaybeLocal GetX509NameObject(Environment* env, X509* cert) { if (value_str_size < 0) { return Undefined(env->isolate()); } + auto free_value_str = OnScopeLeave([&]() { OPENSSL_free(value_str); }); Local v8_value; if (!String::NewFromUtf8(env->isolate(), reinterpret_cast(value_str), NewStringType::kNormal, - value_str_size).ToLocal(&v8_value)) { - OPENSSL_free(value_str); + value_str_size) + .ToLocal(&v8_value)) { return MaybeLocal(); } - OPENSSL_free(value_str); - // For backward compatibility, we only create arrays if multiple values // exist for the same key. That is not great but there is not much we can // change here without breaking things. Note that this creates nested data