From a9a55261b6e31db16ba8b6c6f8c5724c5056ef64 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 19 Jun 2020 16:31:45 +0900 Subject: [PATCH] Fix wrong implementation The FdBroker ptr has to be removed when the FdBroker instance is removed. The FdBroker.Cancel() method can be invoked from the Proxy instance directly. The exceptions about the registration handle are added in the callback functions related to gdbus. Change-Id: Ieb96e393550e3cfa25d29cc4c97ae207cad1dba8 Signed-off-by: Hwankyu Jhun --- src/fdbroker-internal.cc | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index 54ed899..daf3090 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -217,6 +217,7 @@ FdBroker::FdBroker(bool mock) : mock_(mock) { } FdBroker::~FdBroker() { + FdBrokerManager::GetInst().Remove(this); Cancel(); } @@ -224,8 +225,6 @@ void FdBroker::Cancel() { std::lock_guard lock(mutex_); LOGI("FdBroker::Cancel!"); - FdBrokerManager::GetInst().Remove(this); - if (cancellable_) { LOGW("Cancel the send request"); g_cancellable_cancel(cancellable_); @@ -507,11 +506,16 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn, gpointer user_data) { FdBroker* broker = static_cast(user_data); if (!FdBrokerManager::GetInst().Exist(broker)) { - LOGE("No such broker(%p)", broker); + LOGE("No such FdBroker(%p)", broker); return; } std::lock_guard lock(broker->mutex_); + if (broker->registration_id_ == 0) { + LOGE("Invalid context. FdBroker(%p)", broker); + return; + } + int ret = -1; char sender_appid[255]; int sender_pid; @@ -712,11 +716,16 @@ void FdBroker::OnNameAppeared(GDBusConnection *connection, gpointer user_data) { FdBroker* broker = static_cast(user_data); if (!FdBrokerManager::GetInst().Exist(broker)) { - LOGE("No such broker(%p)", broker); + LOGE("No such FdBroker(%p)", broker); return; } std::lock_guard lock(broker->mutex_); + if (broker->watcher_id_ == 0) { + LOGE("Invalid context. FdBroker(%p)", broker); + return; + } + int pid = broker->GetSenderPid(connection, name_owner); char owner_appid[255] = { 0, }; @@ -741,11 +750,16 @@ void FdBroker::OnNameVanished(GDBusConnection *connection, gpointer user_data) { FdBroker* broker = static_cast(user_data); if (!FdBrokerManager::GetInst().Exist(broker)) { - LOGE("No such broker(%p)", broker); + LOGE("No such FdBroker(%p)", broker); return; } std::lock_guard lock(broker->mutex_); + if (broker->watcher_id_ == 0) { + LOGE("Invalid context. FdBroker(%p)", broker); + return; + } + broker->watcher_->OnPortVanished(broker->watch_appid_, broker->watch_port_name_); } @@ -842,6 +856,11 @@ void FdBroker::OnResultReceived(GObject* source_object, } std::lock_guard lock(broker->mutex_); + if (broker->cancellable_ == nullptr) { + LOGE("Invalid context. Fdbroker(%p)", broker); + return; + } + IEventWatcher* watcher = broker->watcher_; if (err) { -- 2.7.4