]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Fix a memory leak report in the distributor unit tests 14224/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 23 May 2024 08:54:05 +0000 (10:54 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 23 May 2024 08:54:05 +0000 (10:54 +0200)
pdns/test-distributor_hh.cc

index 14527c06ab285dd0e6556dfc4b578f8672644cb0..4f1dc4bdb49640fcf8c3203c121197a629219fab 100644 (file)
@@ -67,9 +67,17 @@ struct BackendSlow
 {
   std::unique_ptr<DNSPacket> question(Question&)
   {
-    sleep(1);
+    if (d_shouldSleep) {
+      /* only sleep once per distributor thread, otherwise
+         we are sometimes destroyed before picking up the queued
+         queries, triggering a memory leak reported by Leak Sanitizer */
+      std::this_thread::sleep_for(std::chrono::seconds(1));
+      d_shouldSleep = false;
+    }
     return make_unique<DNSPacket>(true);
   }
+private:
+  bool d_shouldSleep{true};
 };
 
 static std::atomic<int> g_receivedAnswers1;