Fix dbus timer setting location 78/231278/1
authorJusung Son <jusung07.son@samsung.com>
Tue, 21 Apr 2020 03:34:20 +0000 (12:34 +0900)
committerJusung Son <jusung07.son@samsung.com>
Tue, 21 Apr 2020 03:34:20 +0000 (12:34 +0900)
-In a multi-threaded environment, the OnPortAppeared() can be called before setting dbus timer

Change-Id: Iacd9ae66897cc77f38c12d4df9cb87b102f1530a
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/proxy-internal.cc

index a97565a..4ba8b29 100644 (file)
@@ -178,8 +178,14 @@ int Proxy::Connect(std::string appid, std::string port_name,
   listener_ = ev;
   target_appid_ = std::move(appid);
   port_name_ = std::move(port_name);
+
+  if (conn_timer_)
+    g_source_remove(conn_timer_);
+  conn_timer_ = g_timeout_add(10 * 1000, DbusNameTimeout, this);
+
   int r = fd_broker_.Watch(this, target_appid_, port_name_);
   if (r < 0) {
+    g_source_remove(conn_timer_);
     listener_ = nullptr;
     if (r == -EILLEGALACCESS)
       return RPC_PORT_ERROR_PERMISSION_DENIED;
@@ -187,10 +193,6 @@ int Proxy::Connect(std::string appid, std::string port_name,
     return RPC_PORT_ERROR_IO_ERROR;
   }
 
-  if (conn_timer_)
-    g_source_remove(conn_timer_);
-  conn_timer_ = g_timeout_add(10 * 1000, DbusNameTimeout, this);
-
   return RPC_PORT_ERROR_NONE;
 }