From 32628055172430a5b06a3ec5724d774290e86fd6 Mon Sep 17 00:00:00 2001
From: Akseli Lahtinen <akselmo@akselmo.dev>
Date: Mon, 12 Aug 2024 08:20:50 +0000
Subject: [PATCH] pipewireproduce.cpp: Add guard to m_stream

After multiple consecutive KRDP sessions,
m_stream can be null, so add a guard to it to avoid segfault.


(cherry picked from commit c9c8c1a7410463c98bab1d9b47abb71a80804258)

96dc2be6 pipewireproduce.cpp: Add guard to m_stream
a3afdd53 Destroy queued connection if no m_stream or m_encoder is found
6de6cb8f Simplify code

Co-authored-by: Akseli Lahtinen <akselmo@akselmo.dev>
---
 src/pipewireproduce.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/pipewireproduce.cpp b/src/pipewireproduce.cpp
index 8fbf366..8bdcb91 100644
--- a/src/pipewireproduce.cpp
+++ b/src/pipewireproduce.cpp
@@ -152,9 +152,11 @@ void PipeWireProduce::deactivate()
 {
     m_deactivated = true;
 
-    auto streamState = m_stream->state();
-
-    m_stream->setActive(false);
+    auto streamState = PW_STREAM_STATE_PAUSED;
+    if (m_stream) {
+        streamState = m_stream->state();
+        m_stream->setActive(false);
+    }
 
     // If we have not been initialized properly before, ensure we still run any
     // cleanup code and exit the thread, otherwise we risk applications not closing
-- 
GitLab

