From 780efb246a6679f41ea988290bb2d916de16b23a Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 12 Jan 2022 16:39:30 +0100 Subject: [PATCH] dnsdist: Avoid a race if one is careless enough to call Rings::init() from two threads at once --- pdns/dnsdist-rings.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pdns/dnsdist-rings.cc b/pdns/dnsdist-rings.cc index fe35307922..6b044273a4 100644 --- a/pdns/dnsdist-rings.cc +++ b/pdns/dnsdist-rings.cc @@ -35,10 +35,9 @@ void Rings::setCapacity(size_t newCapacity, size_t numberOfShards) void Rings::init() { - if (d_initialized) { + if (d_initialized.exchange(true)) { throw std::runtime_error("Rings::init() should only be called once"); } - d_initialized = true; if (d_numberOfShards <= 1) { d_nbLockTries = 0; -- 2.47.2