From 3faca294178e5c661c7adf036b9e9120b6666312 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 23 May 2024 10:54:05 +0200 Subject: [PATCH] auth: Fix a memory leak report in the distributor unit tests --- pdns/test-distributor_hh.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pdns/test-distributor_hh.cc b/pdns/test-distributor_hh.cc index 14527c06ab..4f1dc4bdb4 100644 --- a/pdns/test-distributor_hh.cc +++ b/pdns/test-distributor_hh.cc @@ -67,9 +67,17 @@ struct BackendSlow { std::unique_ptr 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(true); } +private: + bool d_shouldSleep{true}; }; static std::atomic g_receivedAnswers1; -- 2.47.2