From: Remi Gacogne Date: Wed, 12 Jan 2022 15:39:30 +0000 (+0100) Subject: dnsdist: Avoid a race if one is careless enough to call Rings::init() from two thread... X-Git-Tag: auth-4.7.0-alpha1~65^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F11171%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Avoid a race if one is careless enough to call Rings::init() from two threads at once --- 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;