From 828bdffd053327e1b798e1fd2bf37ef41949e02a Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 15 Jun 2018 15:35:56 +0900 Subject: [PATCH] Fix disconnected event handling - Sets IEventListener to nullptr before calling event callback function. Change-Id: Ibe6c7c1fb9f676167770a2f2cf6d3dae81f58c98 Signed-off-by: Hwankyu Jhun --- src/proxy-internal.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 84038eb..593ca7e 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -53,11 +53,12 @@ Proxy::~Proxy() { gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond, gpointer data) { Proxy* proxy = static_cast(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; } -- 2.7.4