From: Remi Gacogne Date: Mon, 15 Nov 2021 09:17:05 +0000 (+0100) Subject: dnsdist: Apply suggestions from code review (thanks, Otto!) X-Git-Tag: dnsdist-1.7.0-beta1~5^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10920%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Apply suggestions from code review (thanks, Otto!) --- 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;