From 99b19dde2ca5501bacedd24a21bac22e1854ab0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 19 May 2023 11:26:05 -0400
Subject: [PATCH] jamiaccount: remove useless loop

The check in this loop is useless as we already have the transport
that we are searching for. Moreover, locking sipConnsMtx_ from
a pjsip operation (here sipvoiplink) may cause a deadlock.

Change-Id: Ic263d69a3f5518857a93a4a4576a4a63b7fda575
---
 src/jamidht/jamiaccount.cpp | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 480919c5b8..6cba033173 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -346,26 +346,15 @@ JamiAccount::newIncomingCall(const std::string& from,
     JAMI_DEBUG("New incoming call from {:s} with {:d} media", from, mediaList.size());
 
     if (sipTransp) {
-        std::unique_lock<std::mutex> connLock(sipConnsMtx_);
-        for (auto& [key, value] : sipConns_) {
-            if (key.first == from) {
-                // Search for a matching linked SipTransport in connection list.
-                for (auto conIter = value.rbegin(); conIter != value.rend(); conIter++) {
-                    if (conIter->transport != sipTransp)
-                        continue;
-
-                    auto call = Manager::instance().callFactory.newSipCall(shared(),
-                                                                           Call::CallType::INCOMING,
-                                                                           mediaList);
-                    call->setPeerUri(JAMI_URI_PREFIX + from);
-                    call->setPeerNumber(from);
-
-                    call->setSipTransport(sipTransp, getContactHeader(sipTransp));
-
-                    return call;
-                }
-            }
-        }
+        auto call = Manager::instance().callFactory.newSipCall(shared(),
+                                                                Call::CallType::INCOMING,
+                                                                mediaList);
+        call->setPeerUri(JAMI_URI_PREFIX + from);
+        call->setPeerNumber(from);
+
+        call->setSipTransport(sipTransp, getContactHeader(sipTransp));
+
+        return call;
     }
 
     JAMI_ERR("newIncomingCall: can't find matching call for %s", from.c_str());
-- 
GitLab