Skip to content

Commit 461c881

Browse files
committed
Fix asan
1 parent 76718b8 commit 461c881

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/Functions/FunctionsStringHashFixedString.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class OpenSSLProvider
5858
OpenSSLProvider() : ctx_template(EVP_MD_CTX_new(), &EVP_MD_CTX_free)
5959
{
6060
if (!ctx_template)
61-
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_MD_CTX_new() failed: {}", getOpenSSLErrors());
61+
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_MD_CTX_new failed: {}", getOpenSSLErrors());
6262

6363
if (EVP_DigestInit_ex(ctx_template.get(), ProviderImpl::provider(), nullptr) != 1)
6464
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_DigestInit_ex failed: {}", getOpenSSLErrors());
@@ -69,20 +69,14 @@ class OpenSSLProvider
6969
if (!ctx_template)
7070
throw Exception(ErrorCodes::LOGICAL_ERROR, "No context provided");
7171

72-
thread_local EVP_MD_CTX * ctx = [] {
73-
EVP_MD_CTX * c = EVP_MD_CTX_new();
74-
if (!c)
75-
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_MD_CTX_new() failed: {}", getOpenSSLErrors());
76-
return c;
77-
}();
78-
79-
if (EVP_MD_CTX_copy_ex(ctx, ctx_template.get()) != 1)
72+
thread_local EVP_MD_CTX_ptr ctx(EVP_MD_CTX_new(), &EVP_MD_CTX_free);
73+
if (EVP_MD_CTX_copy_ex(ctx.get(), ctx_template.get()) != 1)
8074
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_MD_CTX_copy_ex failed: {}", getOpenSSLErrors());
8175

82-
if (EVP_DigestUpdate(ctx, begin, size) != 1)
76+
if (EVP_DigestUpdate(ctx.get(), begin, size) != 1)
8377
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_DigestUpdate failed: {}", getOpenSSLErrors());
8478

85-
if (EVP_DigestFinal_ex(ctx, out_char_data, nullptr) != 1)
79+
if (EVP_DigestFinal_ex(ctx.get(), out_char_data, nullptr) != 1)
8680
throw Exception(ErrorCodes::OPENSSL_ERROR, "EVP_DigestFinal_ex failed: {}", getOpenSSLErrors());
8781
}
8882

0 commit comments

Comments
 (0)