Skip to content
Browse files
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 <>
Reviewed-By: Daeyeon Jeong <>
Reviewed-By: Darshan Sen <>
Reviewed-By: James M Snell <>
  • Loading branch information
tniessen authored and danielleadams committed Oct 5, 2022
1 parent c7ece46 commit 781ad96227414970456426ec1ecec511a0862ced
Showing 1 changed file with 3 additions and 4 deletions.
@@ -992,18 +992,17 @@ static MaybeLocal<Value> GetX509NameObject(Environment* env, X509* cert) {
if (value_str_size < 0) {
return Undefined(env->isolate());
auto free_value_str = OnScopeLeave([&]() { OPENSSL_free(value_str); });

Local<String> v8_value;
if (!String::NewFromUtf8(env->isolate(),
reinterpret_cast<const char*>(value_str),
value_str_size).ToLocal(&v8_value)) {
.ToLocal(&v8_value)) {
return MaybeLocal<Value>();


// 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

0 comments on commit 781ad96

Please sign in to comment.