From: Remi Gacogne Date: Mon, 22 Feb 2021 16:26:14 +0000 (+0100) Subject: rec: Don't delete aggressive cache entries while they are locked X-Git-Tag: dnsdist-1.6.0-alpha2~12^2~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6cf8f84ffbb4a6a4f943d36dc0160a7de09e3deb;p=thirdparty%2Fpdns.git rec: Don't delete aggressive cache entries while they are locked --- diff --git a/pdns/recursordist/aggressive_nsec.cc b/pdns/recursordist/aggressive_nsec.cc index 053dd2c3a9..ca02233248 100644 --- a/pdns/recursordist/aggressive_nsec.cc +++ b/pdns/recursordist/aggressive_nsec.cc @@ -101,10 +101,16 @@ void AggressiveNSECCache::removeZoneInfo(const DNSName& zone, bool subzones) return; } - std::lock_guard lock((*got)->d_lock); - auto removed = (*got)->d_entries.size(); - d_zones.remove(zone, false); - d_entriesCount -= removed; + /* let's increase the ref count of the shared pointer + so we get the lock, remove the zone from the tree, + then release the lock before the entry is deleted */ + auto entry = *got; + { + std::lock_guard lock(entry->d_lock); + auto removed = entry->d_entries.size(); + d_zones.remove(zone, false); + d_entriesCount -= removed; + } } }