]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix "Pointer to local outside storage" reported by Coverity 12974/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 30 Jun 2023 16:16:03 +0000 (18:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 30 Jun 2023 16:19:41 +0000 (18:19 +0200)
We use a temporary `std::string` for a very short tile after it is no
longer required to exist when adding a new custom metric.
Reported by Coverity as CID 394511.

pdns/dnsdistdist/dnsdist-metrics.cc

index e86439c89e98d8ec2ae143151b746624687e7ab0..268778aef23a26b19abeac276b599c23bc98d423 100644 (file)
@@ -160,12 +160,13 @@ std::optional<std::string> declareCustomMetric(const std::string& name, const st
     return std::string("Unable to declare metric '") + std::string(name) + std::string("': invalid name\n");
   }
 
+  const std::string finalCustomName(customName ? *customName : "");
   if (type == "counter") {
     auto customCounters = s_customCounters.write_lock();
     auto itp = customCounters->insert({name, MutableCounter()});
     if (itp.second) {
       g_stats.entries.write_lock()->emplace_back(Stats::EntryPair{name, &(*customCounters)[name].d_value});
-      dnsdist::prometheus::PrometheusMetricDefinition def{name, "counter", description, customName ? *customName : ""};
+      dnsdist::prometheus::PrometheusMetricDefinition def{name, type, description, finalCustomName};
       addMetricDefinition(def);
     }
   }
@@ -174,7 +175,7 @@ std::optional<std::string> declareCustomMetric(const std::string& name, const st
     auto itp = customGauges->insert({name, MutableGauge()});
     if (itp.second) {
       g_stats.entries.write_lock()->emplace_back(Stats::EntryPair{name, &(*customGauges)[name].d_value});
-      dnsdist::prometheus::PrometheusMetricDefinition def{name, "gauge", description, customName ? *customName : ""};
+      dnsdist::prometheus::PrometheusMetricDefinition def{name, type, description, finalCustomName};
       addMetricDefinition(def);
     }
   }