From: Remi Gacogne Date: Tue, 6 Jan 2026 13:59:41 +0000 (+0100) Subject: dnsdist: Fix small performance issues reported by Coverity X-Git-Tag: rec-5.4.0-beta1~55^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d32b1023b9605d621b482afb941a329c82972dfc;p=thirdparty%2Fpdns.git dnsdist: Fix small performance issues reported by Coverity Mostly copying objects that could be moved, plus a few cases of mistakenly copying objects while looping over them. Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 41a00d2766..f25e41d1f4 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -1724,7 +1724,7 @@ std::shared_ptr getSetTraceAction(const SetTraceActionConfigur if (!logger && !(dnsdist::configuration::yaml::s_inClientMode || dnsdist::configuration::yaml::s_inConfigCheckMode)) { throw std::runtime_error("Unable to find the protobuf logger named '" + std::string(logger_name) + "'"); } - loggers.push_back(logger); + loggers.push_back(std::move(logger)); } dnsdist::actions::SetTraceActionConfiguration actionConfig{ diff --git a/pdns/dnsdistdist/dnsdist-lua-actions.cc b/pdns/dnsdistdist/dnsdist-lua-actions.cc index b5da5a1094..1c3a5546b8 100644 --- a/pdns/dnsdistdist/dnsdist-lua-actions.cc +++ b/pdns/dnsdistdist/dnsdist-lua-actions.cc @@ -254,7 +254,7 @@ void setupLuaActions(LuaContext& luaCtx) loggers.push_back(remote_logger.second); } } - config.remote_loggers = loggers; + config.remote_loggers = std::move(loggers); } config.value = value; config.trace_edns_option = trace_edns_option.value_or(65500); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc index ae04d5f679..56a96b5152 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc @@ -702,14 +702,14 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx) } ede.clearExisting = clearExistingEntries.value_or(true); if (ede.clearExisting) { - dnsResponse.ids.d_extendedErrors = std::make_unique>(std::initializer_list({ede})); + dnsResponse.ids.d_extendedErrors = std::make_unique>(std::initializer_list({std::move(ede)})); } else { if (!dnsResponse.ids.d_extendedErrors) { - dnsResponse.ids.d_extendedErrors = std::make_unique>(std::initializer_list({ede})); + dnsResponse.ids.d_extendedErrors = std::make_unique>(std::initializer_list({std::move(ede)})); } else { - dnsResponse.ids.d_extendedErrors->emplace_back(ede); + dnsResponse.ids.d_extendedErrors->emplace_back(std::move(ede)); } } }); diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index 9d741c4969..1f43157e45 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -541,7 +541,7 @@ void dnsdist_ffi_dnsquestion_set_extended_dns_error(dnsdist_ffi_dnsquestion_t* d ede.error.extraText = std::string(extraText, extraTextSize); } ede.clearExisting = true; - dnsQuestion->dq->ids.d_extendedErrors = std::make_unique>(std::initializer_list({ede})); + dnsQuestion->dq->ids.d_extendedErrors = std::make_unique>(std::initializer_list({std::move(ede)})); } void dnsdist_ffi_dnsquestion_add_extended_dns_error(dnsdist_ffi_dnsquestion_t* dnsQuestion, uint16_t infoCode, const char* extraText, size_t extraTextSize) @@ -553,7 +553,7 @@ void dnsdist_ffi_dnsquestion_add_extended_dns_error(dnsdist_ffi_dnsquestion_t* d } ede.clearExisting = false; if (!dnsQuestion->dq->ids.d_extendedErrors) { - dnsQuestion->dq->ids.d_extendedErrors = std::make_unique>(std::initializer_list({ede})); + dnsQuestion->dq->ids.d_extendedErrors = std::make_unique>(std::initializer_list({std::move(ede)})); } else { dnsQuestion->dq->ids.d_extendedErrors->emplace_back(ede); diff --git a/pdns/dnsdistdist/dnsdist-tcp.cc b/pdns/dnsdistdist/dnsdist-tcp.cc index 37a0864c82..844cbae1ae 100644 --- a/pdns/dnsdistdist/dnsdist-tcp.cc +++ b/pdns/dnsdistdist/dnsdist-tcp.cc @@ -1403,7 +1403,7 @@ static bool processXFRResponse(DNSResponse& dnsResponse) } if (dnsResponse.ids.d_extendedErrors) { - for (auto ede : *dnsResponse.ids.d_extendedErrors) { + for (const auto& ede : *dnsResponse.ids.d_extendedErrors) { dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede); } } diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 2b8c075733..13d8de9976 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -567,7 +567,7 @@ bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse, } if (dnsResponse.ids.d_extendedErrors) { - for (auto ede : *dnsResponse.ids.d_extendedErrors) { + for (const auto& ede : *dnsResponse.ids.d_extendedErrors) { dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede); } } @@ -1407,7 +1407,7 @@ static bool prepareOutgoingResponse([[maybe_unused]] const ClientState& clientSt } if (dnsResponse.ids.d_extendedErrors) { - for (auto ede : *dnsResponse.ids.d_extendedErrors) { + for (const auto& ede : *dnsResponse.ids.d_extendedErrors) { dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede); } }