diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp index 4b6b164567a4a237b260c9bf1aa97ad34a7b8c2e..b70cc1ac2f1507f438a3c481be92df1d3f44c294 100644 --- a/src/jamidht/conversation_module.cpp +++ b/src/jamidht/conversation_module.cpp @@ -568,25 +568,27 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer, onNeedSocket_( conversationId, deviceId, - [this, + [w = weak(), conv, conversationId = std::move(conversationId), peer = std::move(peer), deviceId = std::move(deviceId), commitId = std::move(commitId)](const auto& channel) { - std::lock_guard lk(conv->mtx); - // auto conversation = conversations_.find(conversationId); - auto acc = account_.lock(); - if (!channel || !acc || !conv->conversation) { + auto sthis = w.lock(); + auto acc = sthis ? sthis->account_.lock() : nullptr; + std::unique_lock lk(conv->mtx); + auto conversation = conv->conversation; + if (!channel || !acc || !conversation) { conv->stopFetch(deviceId); - syncCnt.fetch_sub(1); + if (sthis) sthis->syncCnt.fetch_sub(1); return false; } - conv->conversation->addGitSocket(channel->deviceId(), channel); - conv->conversation->sync( + conversation->addGitSocket(channel->deviceId(), channel); + lk.unlock(); + conversation->sync( peer, deviceId, - [w = weak(), + [w, conv, conversationId = std::move(conversationId), peer = std::move(peer),