diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index c278245ac6809fbcf2c3890e782d72b6e71eeb7f..f4f38035c1fb25abaa83c643758e7964e243b6ce 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2077,7 +2077,6 @@ JamiAccount::doRegister_() // TODO replace auto isFile = name.substr(0, 7) == FILE_URI; auto isVCard = name.substr(0, 8) == VCARD_URI; - auto isDataTransfer = name.substr(0, 16) == DATA_TRANSFER_URI; if (name == "sip") { return true; @@ -2253,6 +2252,7 @@ JamiAccount::convModule() JAMI_ERR() << "Calling convModule() with an uninitialized account."; return nullptr; } + std::lock_guard<std::mutex> lk(moduleMtx_); if (!convModule_) { convModule_ = std::make_unique<ConversationModule>( weak(), @@ -2324,6 +2324,7 @@ JamiAccount::syncModule() JAMI_ERR() << "Calling syncModule() with an uninitialized account."; return nullptr; } + std::lock_guard<std::mutex> lk(moduleMtx_); if (!syncModule_) syncModule_ = std::make_unique<SyncModule>(weak()); return syncModule_.get(); diff --git a/src/jamidht/jamiaccount.h b/src/jamidht/jamiaccount.h index 9396e94ff12a1338e4927220cd84036990118086..c8aef36d8654913b6b2e46c6ca117592526502f8 100644 --- a/src/jamidht/jamiaccount.h +++ b/src/jamidht/jamiaccount.h @@ -908,6 +908,7 @@ private: std::map<Uri::Scheme, std::unique_ptr<ChannelHandlerInterface>> channelHandlers_ {}; std::unique_ptr<ConversationModule> convModule_; + std::mutex moduleMtx_; std::unique_ptr<SyncModule> syncModule_; void initConnectionManager(); diff --git a/src/jamidht/sync_channel_handler.cpp b/src/jamidht/sync_channel_handler.cpp index c8daa55925dee11ee90d53f6bfe55b491b6eca2a..7f9cde8dce1279ef0363fe79013d6e11d1439527 100644 --- a/src/jamidht/sync_channel_handler.cpp +++ b/src/jamidht/sync_channel_handler.cpp @@ -51,7 +51,8 @@ SyncChannelHandler::connect(const DeviceId& deviceId, const std::string&, Connec } bool -SyncChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, const std::string& /* name */) +SyncChannelHandler::onRequest(const std::shared_ptr<dht::crypto::Certificate>& cert, + const std::string& /* name */) { auto acc = account_.lock(); if (!cert || !cert->issuer || !acc) @@ -65,9 +66,12 @@ SyncChannelHandler::onReady(const std::shared_ptr<dht::crypto::Certificate>& cer std::shared_ptr<ChannelSocket> channel) { auto acc = account_.lock(); - if (!cert || !cert->issuer || !acc || !acc->syncModule()) + if (!cert || !cert->issuer || !acc) return; - acc->syncModule()->cacheSyncConnection(std::move(channel), cert->issuer->getId().toString(), cert->getLongId()); + if (auto sm = acc->syncModule()) + sm->cacheSyncConnection(std::move(channel), + cert->issuer->getId().toString(), + cert->getLongId()); } } // namespace jami \ No newline at end of file