]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Don't delete aggressive cache entries while they are locked
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Feb 2021 16:26:14 +0000 (17:26 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Feb 2021 17:44:07 +0000 (18:44 +0100)
pdns/recursordist/aggressive_nsec.cc

index 053dd2c3a9fa3a7c138f81b0777e609ad43fea7e..ca02233248d1f7996865b3578f06d5d9d1f01b86 100644 (file)
@@ -101,10 +101,16 @@ void AggressiveNSECCache::removeZoneInfo(const DNSName& zone, bool subzones)
       return;
     }
 
-    std::lock_guard<std::mutex> 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<std::mutex> lock(entry->d_lock);
+      auto removed = entry->d_entries.size();
+      d_zones.remove(zone, false);
+      d_entriesCount -= removed;
+    }
   }
 }