From ae1f2720158ad51e0699872a6f6dac9ec11b4909 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Thu, 15 Feb 2024 13:18:14 -0500
Subject: [PATCH] Conversation: capture weak_ptr for onNeedSocket

Change-Id: Ic0a31aa42ebf17002843027d443846a2052c2e0b
---
 src/jamidht/conversation.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp
index 335f18271c..045fdb600b 100644
--- a/src/jamidht/conversation.cpp
+++ b/src/jamidht/conversation.cpp
@@ -2307,10 +2307,12 @@ void
 Conversation::onNeedSocket(NeedSocketCb needSocket)
 {
     pimpl_->swarmManager_->needSocketCb_ = [needSocket = std::move(needSocket),
-                                            this](const std::string& deviceId, ChannelCb&& cb) {
-        return needSocket(id(), deviceId, std::move(cb), "application/im-gitmessage-id");
+                                            w=weak()](const std::string& deviceId, ChannelCb&& cb) {
+        if (auto sthis = w.lock())
+            needSocket(sthis->id(), deviceId, std::move(cb), "application/im-gitmessage-id");
     };
 }
+
 void
 Conversation::addSwarmChannel(std::shared_ptr<dhtnet::ChannelSocket> channel)
 {
-- 
GitLab