From: Otto Moerbeek Date: Mon, 10 Nov 2025 13:50:37 +0000 (+0100) Subject: Avoid leak by using a smart pointer X-Git-Tag: rec-5.4.0-alpha1~40^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=915834be5c561fce8b05e5f49ebe19570e0c6a3a;p=thirdparty%2Fpdns.git Avoid leak by using a smart pointer Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/rec_channel_rec.cc b/pdns/recursordist/rec_channel_rec.cc index be85498427..86bcc8b371 100644 --- a/pdns/recursordist/rec_channel_rec.cc +++ b/pdns/recursordist/rec_channel_rec.cc @@ -116,7 +116,7 @@ static map> d_getmultimembers; struct dynmetrics { - std::atomic* d_ptr; + std::unique_ptr> d_ptr; std::string d_prometheusName; std::optional d_prometheusType; std::optional d_prometheusDescr; @@ -183,7 +183,7 @@ std::atomic* getDynMetric(const std::string& str, const std::stri auto locked = d_dynmetrics.lock(); auto iter = locked->find(str); if (iter != locked->end()) { - return iter->second.d_ptr; + return iter->second.d_ptr.get(); } std::string name = prometheusName.empty() ? getPrometheusName(str) : prometheusName; @@ -201,9 +201,11 @@ std::atomic* getDynMetric(const std::string& str, const std::stri descr = prometheusDescr; } - auto ret = dynmetrics{new std::atomic(), std::move(name), metricType, std::move(descr)}; - (*locked)[str] = ret; - return ret.d_ptr; + auto uptr = std::make_unique>(0); + auto* ptr = uptr.get(); + auto ret = dynmetrics{std::move(uptr), std::move(name), metricType, std::move(descr)}; + (*locked)[str] = std::move(ret); + return ptr; } static std::optional get(const string& name)