Merge "Fix crashes detected by grpc_graph_fuzzer" into rvc-qpr-dev
diff --git a/computepipe/runner/graph/GrpcGraph.cpp b/computepipe/runner/graph/GrpcGraph.cpp
index efd56c9..07e2656 100644
--- a/computepipe/runner/graph/GrpcGraph.cpp
+++ b/computepipe/runner/graph/GrpcGraph.cpp
@@ -171,7 +171,7 @@
 // Starts the graph.
 Status GrpcGraph::handleExecutionPhase(const runner::RunnerEvent& e) {
     std::lock_guard lock(mLock);
-    if (mGraphState != PrebuiltGraphState::STOPPED) {
+    if (mGraphState != PrebuiltGraphState::STOPPED || mStreamSetObserver == nullptr) {
         mStatus = Status::ILLEGAL_STATE;
         return mStatus;
     }
diff --git a/computepipe/runner/graph/StreamSetObserver.cpp b/computepipe/runner/graph/StreamSetObserver.cpp
index 2586b51..513ee44 100644
--- a/computepipe/runner/graph/StreamSetObserver.cpp
+++ b/computepipe/runner/graph/StreamSetObserver.cpp
@@ -157,6 +157,9 @@
     std::unique_lock lock(mLock);
     if (mStopped) {
         // Separate thread is necessary here to avoid recursive locking.
+        if (mGraphTerminationThread.joinable()) {
+            mGraphTerminationThread.join();
+        }
         mGraphTerminationThread = std::thread([this]() {
             this->mStreamGraphInterface->dispatchGraphTerminationMessage(Status::SUCCESS, "");
         });