Skip to content

Commit f5f12f3

Browse files
authored
impl(rest): add synchronization when calling curl_version_info (googleapis#16271)
1 parent 93c8274 commit f5f12f3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

google/cloud/internal/ssl_ec_curves.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ namespace {
3232
constexpr unsigned int kMinimumLibcurlVersionForEcCurves =
3333
(7U << 16) | (73U << 8) | 0U;
3434

35+
// `curl_version_info()` is not thread-safe as libcurl constructs version
36+
// string details in internal static buffers without locks. Using a block-scope
37+
// static ensures thread-safe initialization exactly once via C++11 magic
38+
// statics, preventing data races when multiple threads create REST clients.
3539
bool SupportsSslEcCurves() {
36-
auto* vinfo = curl_version_info(CURLVERSION_NOW);
37-
return vinfo != nullptr &&
38-
vinfo->version_num >= kMinimumLibcurlVersionForEcCurves;
40+
static bool const kSupports = [] {
41+
auto* vinfo = curl_version_info(CURLVERSION_NOW);
42+
return vinfo != nullptr &&
43+
vinfo->version_num >= kMinimumLibcurlVersionForEcCurves;
44+
}();
45+
return kSupports;
3946
}
4047

4148
} // namespace

0 commit comments

Comments
 (0)