Skip to content

Commit 781ad96

Browse files
tniessendanielleadams
authored andcommitted
src: use OnScopeLeave instead of multiple free()
This is not great either but it avoids having to call OPENSSL_free() in more than one branch, thus reducing the risk of memory leaks. PR-URL: #44852 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c7ece46 commit 781ad96

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/crypto/crypto_common.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -992,18 +992,17 @@ static MaybeLocal<Value> GetX509NameObject(Environment* env, X509* cert) {
992992
if (value_str_size < 0) {
993993
return Undefined(env->isolate());
994994
}
995+
auto free_value_str = OnScopeLeave([&]() { OPENSSL_free(value_str); });
995996

996997
Local<String> v8_value;
997998
if (!String::NewFromUtf8(env->isolate(),
998999
reinterpret_cast<const char*>(value_str),
9991000
NewStringType::kNormal,
1000-
value_str_size).ToLocal(&v8_value)) {
1001-
OPENSSL_free(value_str);
1001+
value_str_size)
1002+
.ToLocal(&v8_value)) {
10021003
return MaybeLocal<Value>();
10031004
}
10041005

1005-
OPENSSL_free(value_str);
1006-
10071006
// For backward compatibility, we only create arrays if multiple values
10081007
// exist for the same key. That is not great but there is not much we can
10091008
// change here without breaking things. Note that this creates nested data

0 commit comments

Comments
 (0)