Skip to content

Commit

Permalink
src: use OnScopeLeave instead of multiple free()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
tniessen authored and danielleadams committed Oct 5, 2022
1 parent c7ece46 commit 781ad96
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
NewStringType::kNormal,
value_str_size).ToLocal(&v8_value)) {
OPENSSL_free(value_str);
value_str_size)
.ToLocal(&v8_value)) {
return MaybeLocal<Value>();
}

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
Expand Down

0 comments on commit 781ad96

Please sign in to comment.