From 701180b53d1c52376f753b94c5cf09987ae789b3 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Tue, 18 Jun 2024 16:02:25 +0800
Subject: [PATCH 114/149] bugfix for null pointer reference

Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
 src/daemon/entry/connect/grpc/grpc_service.cc | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/daemon/entry/connect/grpc/grpc_service.cc b/src/daemon/entry/connect/grpc/grpc_service.cc
index 1d8de922..300af082 100644
--- a/src/daemon/entry/connect/grpc/grpc_service.cc
+++ b/src/daemon/entry/connect/grpc/grpc_service.cc
@@ -100,7 +100,9 @@ public:
     {
         // Wait for the server to shutdown. Note that some other thread must be
         // responsible for shutting down the server for this call to ever return.
-        m_server->Wait();
+        if (m_server != nullptr) {
+            m_server->Wait();
+        }
 
         // Wait for stream server to shutdown
         m_criService.Wait();
@@ -109,7 +111,9 @@ public:
     void Shutdown(void)
     {
         // call CRI to shutdown stream server, shutdown cri first to notify events thread to exit
-        m_criService.Shutdown();
+        if (m_server != nullptr) {
+            m_server->Shutdown();
+        }
 
         m_server->Shutdown();
 
@@ -242,10 +246,16 @@ int grpc_server_init(const struct service_arguments *args)
 
 void grpc_server_wait(void)
 {
+    if (g_grpcserver == nullptr) {
+        return;
+    }
     g_grpcserver->Wait();
 }
 
 void grpc_server_shutdown(void)
 {
+    if (g_grpcserver == nullptr) {
+        return;
+    }
     g_grpcserver->Shutdown();
 }
-- 
2.25.1

