]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
pthread_rwlock_init() should be matched by pthread_rwlock_destroy() 8580/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 26 Nov 2019 12:24:59 +0000 (13:24 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 26 Nov 2019 12:39:34 +0000 (13:39 +0100)
On some platforms, pthread_rwlock_init() not only inits mem, but also
acquires resources.

12 files changed:
pdns/auth-packetcache.cc
pdns/auth-packetcache.hh
pdns/auth-querycache.cc
pdns/auth-querycache.hh
pdns/dnscrypt.cc
pdns/dnscrypt.hh
pdns/dnsdist-cache.hh
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-kvs.cc
pdns/dnsdistdist/dnsdist-kvs.hh
pdns/dnsdistdist/dnsdist-rules.hh
pdns/test-lock_hh.cc

index 715a5008f8a688a1e192b935be68b9b6327cad63..7f9b2c1aa60c25b95bb4ea484f589130a6ac5dad 100644 (file)
@@ -33,9 +33,6 @@ const unsigned int AuthPacketCache::s_mincleaninterval, AuthPacketCache::s_maxcl
 AuthPacketCache::AuthPacketCache(size_t mapsCount): d_lastclean(time(nullptr))
 {
   d_maps.resize(mapsCount);
-  for(auto& mc : d_maps) {
-    pthread_rwlock_init(&mc.d_mut, 0);
-  }
 
   S.declare("packetcache-hit", "Number of hits on the packet cache");
   S.declare("packetcache-miss", "Number of misses on the packet cache");
index 94dad631df417dc2ba8cffad0b9c19779ebb27c2..91a9798c2774e3384669403b158b99fc6269b476 100644 (file)
@@ -104,7 +104,13 @@ private:
 
   struct MapCombo
   {
-    pthread_rwlock_t d_mut;    
+    MapCombo() {
+      pthread_rwlock_init(&d_mut, nullptr);
+    }
+    ~MapCombo() {
+      pthread_rwlock_destroy(&d_mut);
+    }
+    pthread_rwlock_t d_mut;
     cmap_t d_map;
   };
 
index 033ed32312f08595922749be930833c32fedb57b..578c96439a7a6b3bec84c752f51324f755c1bd22 100644 (file)
@@ -34,9 +34,6 @@ const unsigned int AuthQueryCache::s_mincleaninterval, AuthQueryCache::s_maxclea
 AuthQueryCache::AuthQueryCache(size_t mapsCount): d_lastclean(time(nullptr))
 {
   d_maps.resize(mapsCount);
-  for(auto& mc : d_maps) {
-    pthread_rwlock_init(&mc.d_mut, 0);
-  }
 
   S.declare("query-cache-hit","Number of hits on the query cache");
   S.declare("query-cache-miss","Number of misses on the query cache");
index 21e35add37f9beec47497f4e0a27933eaecaed70..6827c538749c2bbb7285b41b326af891d692f261 100644 (file)
@@ -87,7 +87,13 @@ private:
 
   struct MapCombo
   {
-    pthread_rwlock_t d_mut;    
+    MapCombo() {
+      pthread_rwlock_init(&d_mut, nullptr);
+    }
+    ~MapCombo() {
+      pthread_rwlock_destroy(&d_mut);
+    }
+    pthread_rwlock_t d_mut;
     cmap_t d_map;
   };
 
index c18d29e2c5e5a14bcc775399b7f254eec17a44ba..71535acdf6a64266a992bda517bc9b72bf561970 100644 (file)
@@ -123,6 +123,11 @@ DNSCryptQuery::~DNSCryptQuery()
 }
 #endif /* HAVE_CRYPTO_BOX_EASY_AFTERNM */
 
+
+DNSCryptContext::~DNSCryptContext() {
+  pthread_rwlock_destroy(&d_lock);
+}
+
 DNSCryptContext::DNSCryptContext(const std::string& pName, const std::vector<CertKeyPaths>& certKeys): d_certKeyPaths(certKeys), providerName(pName)
 {
   pthread_rwlock_init(&d_lock, 0);
index 3026ec17853d6fbe2403b53a893ee93ca663ff5b..53b09f5fadf52c7b7b0baaed9a8ed4ab0ba2f44b 100644 (file)
@@ -262,7 +262,8 @@ public:
 
   DNSCryptContext(const std::string& pName, const std::vector<CertKeyPaths>& certKeys);
   DNSCryptContext(const std::string& pName, const DNSCryptCert& certificate, const DNSCryptPrivateKey& pKey);
-
+  ~DNSCryptContext();
+  
   void reloadCertificates();
   void loadNewCertificate(const std::string& certFile, const std::string& keyFile, bool active=true, bool reload=false);
   void addNewCertificate(const DNSCryptCert& newCert, const DNSCryptPrivateKey& newKey, bool active=true, bool reload=false);
index 887f03d32bf63d01158cb1c9a0192f495778241a..4b03ad4151aede5e3e748a6a47e90b36c79ce753 100644 (file)
@@ -92,13 +92,15 @@ private:
   public:
     CacheShard(): d_entriesCount(0)
     {
-      pthread_rwlock_init(&d_lock, 0);
+      pthread_rwlock_init(&d_lock, nullptr);
     }
     CacheShard(const CacheShard& old): d_entriesCount(0)
     {
-      pthread_rwlock_init(&d_lock, 0);
+      pthread_rwlock_init(&d_lock, nullptr);
+    }
+    ~CacheShard() {
+      pthread_rwlock_destroy(&d_lock);
     }
-
     void setSize(size_t maxSize)
     {
       d_map.reserve(maxSize);
index 69bc7833627e162db964debde7fd4d04d2ac0200..cc92cac7009b4cce2c50095f292e3581cf38fe15 100644 (file)
@@ -655,6 +655,10 @@ struct QueryCount {
   {
     pthread_rwlock_init(&queryLock, nullptr);
   }
+  ~QueryCount()
+  {
+    pthread_rwlock_destroy(&queryLock);
+  }
   QueryCountRecords records;
   QueryCountFilter filter;
   pthread_rwlock_t queryLock;
@@ -845,6 +849,7 @@ struct DownstreamState
         fd = -1;
       }
     }
+    pthread_rwlock_destroy(&d_lock);
   }
   boost::uuids::uuid id;
   std::set<unsigned int> hashes;
@@ -1000,6 +1005,10 @@ struct ServerPool
   {
     pthread_rwlock_init(&d_lock, nullptr);
   }
+  ~ServerPool()
+  {
+    pthread_rwlock_destroy(&d_lock);
+  }
 
   const std::shared_ptr<DNSDistPacketCache> getCache() const { return packetCache; };
 
index 67976d9c98ee3676bc9f1b7efaf85a60d885f211..97e4cb301a42d477c2b04d4f8deb6483466c7af9 100644 (file)
@@ -128,6 +128,10 @@ CDBKVStore::CDBKVStore(const std::string& fname, time_t refreshDelay): d_fname(f
   refreshDBIfNeeded(now);
 }
 
+CDBKVStore::~CDBKVStore() {
+  pthread_rwlock_destroy(&d_lock);
+}
+
 bool CDBKVStore::reload(const struct stat& st)
 {
   auto newCDB = std::unique_ptr<CDB>(new CDB(d_fname));
index 5cbd2b085a9d05bd172d910fc34cf774d3d21f69..63e18fdf5e507e94be14b45bfd79db8911fc190d 100644 (file)
@@ -181,6 +181,7 @@ class CDBKVStore: public KeyValueStore
 {
 public:
   CDBKVStore(const std::string& fname, time_t refreshDelay);
+  ~CDBKVStore();
 
   bool keyExists(const std::string& key) override;
   bool getValue(const std::string& key, std::string& value) override;
index e443fd3425e606d4f5d0387953c0e7f2c04f42f3..b4487badf107933b4fbee60d05d154117ab1be06 100644 (file)
@@ -235,6 +235,11 @@ public:
     pthread_rwlock_init(&d_lock4, 0);
     pthread_rwlock_init(&d_lock6, 0);
   }
+  ~TimedIPSetRule()
+  {
+    pthread_rwlock_destroy(&d_lock4);
+    pthread_rwlock_destroy(&d_lock6);
+  }
   bool matches(const DNSQuestion* dq) const override
   {
     if(dq->remote->sin4.sin_family == AF_INET) {
index abb813102e68dda49ea2cb57f1a99c1f4c73cad3..03e75541195044c611490990d3c1de2805a3efa0 100644 (file)
@@ -57,7 +57,9 @@ BOOST_AUTO_TEST_CASE(test_pdns_lock)
   TryReadLock trl2(&*g_locks[0]);
   BOOST_CHECK(trl2.gotIt());
   
-  
+  for(auto& pp : g_locks) {
+    pthread_rwlock_destroy(pp.get());
+  }  
 }
 
 BOOST_AUTO_TEST_SUITE_END()