From b6504373145c5505d87bb9620e2daa1d86d44181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 12 Oct 2023 10:35:35 -0400 Subject: [PATCH] connectionmanager: pass weak to dht()->getPublicAddress() dht() can live longer, so technically there is nothing preventing this to be nullptr there Change-Id: Ifc77f1a9c8e3b3d889da16056a7e8965ec4786ed --- src/connectionmanager.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/connectionmanager.cpp b/src/connectionmanager.cpp index 62fb4ef..cf78c54 100644 --- a/src/connectionmanager.cpp +++ b/src/connectionmanager.cpp @@ -1474,27 +1474,30 @@ ConnectionManager::Impl::setPublishedAddress(const IpAddr& ip_addr) void ConnectionManager::Impl::storeActiveIpAddress(std::function<void()>&& cb) { - dht()->getPublicAddress([this, cb = std::move(cb)](std::vector<dht::SockAddr>&& results) { + dht()->getPublicAddress([w=weak(), cb = std::move(cb)](std::vector<dht::SockAddr>&& results) { + auto shared = w.lock(); + if (!shared) + return; bool hasIpv4 {false}, hasIpv6 {false}; for (auto& result : results) { auto family = result.getFamily(); if (family == AF_INET) { if (not hasIpv4) { hasIpv4 = true; - if (config_->logger) - config_->logger->debug("Store DHT public IPv4 address: {}", result); + if (shared->config_->logger) + shared->config_->logger->debug("Store DHT public IPv4 address: {}", result); //JAMI_DBG("Store DHT public IPv4 address : %s", result.toString().c_str()); - setPublishedAddress(*result.get()); - if (config_->upnpCtrl) { - config_->upnpCtrl->setPublicAddress(*result.get()); + shared->setPublishedAddress(*result.get()); + if (shared->config_->upnpCtrl) { + shared->config_->upnpCtrl->setPublicAddress(*result.get()); } } } else if (family == AF_INET6) { if (not hasIpv6) { hasIpv6 = true; - if (config_->logger) - config_->logger->debug("Store DHT public IPv6 address: {}", result); - setPublishedAddress(*result.get()); + if (shared->config_->logger) + shared->config_->logger->debug("Store DHT public IPv6 address: {}", result); + shared->setPublishedAddress(*result.get()); } } if (hasIpv4 and hasIpv6) -- GitLab