From 1877effeea112d7153d4a4380d1e9aeefbbf6e9c Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 15 Nov 2021 10:17:05 +0100 Subject: [PATCH] dnsdist: Apply suggestions from code review (thanks, Otto!) --- pdns/dnsdistdist/dnsdist-tcp-downstream.hh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh index 489405ef1e..f85fc36e5e 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh @@ -374,7 +374,7 @@ public: return newConnection; } - void cleanupClosedConnections(struct timeval now) + void cleanupClosedConnections(const struct timeval& now) { if (s_cleanupInterval == 0 || (d_nextCleanup != 0 && d_nextCleanup > now.tv_sec)) { return; @@ -524,7 +524,7 @@ protected: } } - std::shared_ptr findUsableConnectionInList(const struct timeval& now, struct timeval& freshCutOff, list_t& list, bool removeIfFound) + std::shared_ptr findUsableConnectionInList(const struct timeval& now, const struct timeval& freshCutOff, list_t& list, bool removeIfFound) { auto& sidx = list.template get(); for (auto listIt = sidx.begin(); listIt != sidx.end(); ) { @@ -536,6 +536,7 @@ protected: auto& entry = *listIt; if (isConnectionUsable(entry, now, freshCutOff)) { entry->setReused(); + // make a copy since the iterator will be invalidated after erasing auto result = entry; if (removeIfFound) { sidx.erase(listIt); @@ -568,11 +569,7 @@ protected: return true; } - if (conn->isUsable()) { - return true; - } - - return false; + return conn->isUsable(); } static size_t s_maxIdleConnectionsPerDownstream; -- 2.47.2