Fix crashes detected by grpc_graph_fuzzer

Bug: 174785162
Bug: 168285457
Test: Follow go/android-fuzzing to build and test

Change-Id: I8409807d1ef88b1afbf7e603c402a8584f3cd913
Merged-In: I8409807d1ef88b1afbf7e603c402a8584f3cd913
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, "");
         });