Add exception handling about main port check 70/244370/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Sep 2020 22:27:45 +0000 (07:27 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 17 Sep 2020 22:54:56 +0000 (07:54 +0900)
We should check whether the main port is deleted or not. While calling
rpc_port_proxy_destroy(), the main port is deleted.
When the disconnected event is delivered, the proxy app will have crashed
if it is accessing the fd getter.
This patch adds the exceptions to check whether the main port is nullptr or not.

Change-Id: Ib68f53616091e8079a1831e56504ad9a228df818
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/proxy-internal.cc

index 224ea34ae707e40a9e5e564bd4847916d6f8afb2..90e54aac542702c823e746e1325ea366ed7d986c 100644 (file)
@@ -47,7 +47,7 @@ gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
 
   _W("Socket was disconnected. fd(%d)", fd);
 
-  if (proxy->main_port_->GetFd() == fd) {
+  if (proxy->main_port_.get() != nullptr && proxy->main_port_->GetFd() == fd) {
     proxy->listener_ = nullptr;
     proxy->main_port_->SetDisconnectedSource(0);
     if (listener)
@@ -84,8 +84,10 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond,
       if (listener)
         listener->OnDisconnected(proxy->target_appid_);
 
-      DebugPort::GetInst().RemoveSession(proxy->main_port_->GetFd());
-      proxy->main_port_.reset();
+      if (proxy->main_port_.get() != nullptr) {
+        DebugPort::GetInst().RemoveSession(proxy->main_port_->GetFd());
+        proxy->main_port_.reset();
+      }
       proxy->delegate_port_.reset();
       return FALSE;
     }
@@ -245,6 +247,7 @@ int Proxy::ConnectSync(std::string appid, std::string port_name,
 }
 
 void Proxy::DisconnectPort() {
+  DebugPort::GetInst().RemoveSession(main_port_->GetFd());
   main_port_.reset();
 }