From 40fdd04cb344a3bff97da6f7407511bc91be56f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Fri, 16 Apr 2021 15:13:07 -0400
Subject: [PATCH] dht: cleanup handling of onConnectCallback

---
 src/dht.cpp              | 8 ++++----
 src/dht_proxy_client.cpp | 3 +--
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/dht.cpp b/src/dht.cpp
index bbd2b958..331e418b 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -1984,10 +1984,10 @@ Dht::onConnected()
         bootstrapJob.reset();
     }
     bootstrap_period = std::chrono::seconds(10);
-    while (not onConnectCallbacks_.empty()) {
-        auto cb = std::move(onConnectCallbacks_.front());
-        onConnectCallbacks_.pop();
-        cb();
+    auto callbacks = std::move(onConnectCallbacks_);
+    while (not callbacks.empty()) {
+        callbacks.front()();
+        callbacks.pop();
     }
 }
 
diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp
index ab7b86cd..60cd50d5 100644
--- a/src/dht_proxy_client.cpp
+++ b/src/dht_proxy_client.cpp
@@ -727,9 +727,8 @@ DhtProxyClient::onProxyInfos(const Json::Value& proxyInfos, const sa_family_t fa
                 std::lock_guard<std::mutex> lock(lockCallbacks_);
                 callbacks_.emplace_back([cbs = std::move(onConnectCallbacks_)]() mutable {
                     while (not cbs.empty()) {
-                        auto cb = std::move(cbs.front());
+                        cbs.front()();
                         cbs.pop();
-                        cb();
                     }
                 });
             }
-- 
GitLab