From: Remi Gacogne Date: Thu, 23 May 2024 08:54:05 +0000 (+0200) Subject: auth: Fix a memory leak report in the distributor unit tests X-Git-Tag: rec-5.1.0-beta1~28^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14224%2Fhead;p=thirdparty%2Fpdns.git auth: Fix a memory leak report in the distributor unit tests --- 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;