Fix disconnected event handling
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 15 Jun 2018 06:35:56 +0000 (15:35 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 15 Jun 2018 08:01:47 +0000 (17:01 +0900)
- Sets IEventListener to nullptr before calling event callback function.

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

index 84038eb..593ca7e 100644 (file)
@@ -53,11 +53,12 @@ Proxy::~Proxy() {
 gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
                                      gpointer data) {
   Proxy* proxy = static_cast<Proxy*>(data);
+  IEventListener* listener = proxy->listener_;
 
   LOGW("Socket was disconnected");
-  proxy->listener_->OnDisconnected(proxy->target_appid_);
+  proxy->listener_ = nullptr;
   proxy->disconn_src_ = 0;
-
+  listener->OnDisconnected(proxy->target_appid_);
   return FALSE;
 }
 
@@ -69,8 +70,10 @@ gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond,
 
   if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
     LOGW("Socket was disconnected by stub");
-    proxy->listener_->OnDisconnected(proxy->target_appid_);
+    IEventListener* listener = proxy->listener_;
+    proxy->listener_ = nullptr;
     proxy->src_ = 0;
+    listener->OnDisconnected(proxy->target_appid_);
     return FALSE;
   }
 
@@ -116,8 +119,10 @@ int Proxy::Watch(int fd) {
 void Proxy::OnPortRejected(const std::string& appid) {
   if (listener_ == nullptr)
     return;
-  listener_->OnRejected(appid);
+
+  IEventListener* listener = listener_;
   listener_ = nullptr;
+  listener->OnRejected(appid);
 }
 
 void Proxy::OnPortAppeared(const std::string& appid,
@@ -129,8 +134,9 @@ void Proxy::OnPortAppeared(const std::string& appid,
 
   int fd = fd_broker_.Send(appid, port_name);
   if (fd <= 0) {
-    listener_->OnRejected(appid);
+    IEventListener* listener = listener_;
     listener_ = nullptr;
+    listener->OnRejected(appid);
     return;
   }