From 0c98f2b1ffd8528ec26a0d4abc67a6de3067263a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Sat, 19 Mar 2022 18:46:10 -0400
Subject: [PATCH] sipcall: do not use invalid pointer on videoRtp

Change-Id: Iccd5fa02855fb8dc33529177e2fb14d7588add44
---
 src/sip/sipcall.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp
index 70cd5b24c2..a253ed344e 100644
--- a/src/sip/sipcall.cpp
+++ b/src/sip/sipcall.cpp
@@ -2147,18 +2147,18 @@ SIPCall::stopAllMedia()
         audioRtp->stop();
 #ifdef ENABLE_VIDEO
     auto const& videoRtp = getVideoRtp();
-
     {
         std::lock_guard<std::mutex> lk(sinksMtx_);
-        auto& videoReceive = videoRtp->getVideoReceive();
-        if (videoReceive) {
-            auto& sink = videoReceive->getSink();
-            for (auto it = callSinksMap_.begin(); it != callSinksMap_.end();) {
-                sink->detach(it->second.get());
-
-                it->second->stop();
-                it = callSinksMap_.erase(it);
+        for (auto it = callSinksMap_.begin(); it != callSinksMap_.end();) {
+            if (videoRtp) {
+                auto& videoReceive = videoRtp->getVideoReceive();
+                if (videoReceive) {
+                    auto& sink = videoReceive->getSink();
+                    sink->detach(it->second.get());
+                }
             }
+            it->second->stop();
+            it = callSinksMap_.erase(it);
         }
     }
 
-- 
GitLab