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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Tobias Nießen authored and Danielle Adams committed 2022-10-05 11:54:20 +01:00
1 parent c7ece464a1
commit 781ad96227
1 file changed
+3 -4
+3 -4
View File
@@ -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