Changes code for defensing gdbus race condition 95/236095/1
authorInkyun Kil <inkyun.kil@samsung.com>
Mon, 15 Jun 2020 00:27:06 +0000 (09:27 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Mon, 15 Jun 2020 00:27:06 +0000 (09:27 +0900)
Change-Id: Iae66d7c5c4298bc41e41f1325d60cead843ad32f
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
server/alarm-manager-dbus.c

index db290cc..42cb1f2 100644 (file)
@@ -750,19 +750,6 @@ static void __on_bus_name_acquired(GDBusConnection  *connection,
                                gpointer user_data)
 {
        LOGD("bus acquired(%s)", name);
-
-       guint reg_id = 0;
-       GError *error = NULL;
-
-       reg_id = g_dbus_connection_register_object(connection,
-               ALARM_MGR_DBUS_PATH,
-               introspection_data->interfaces[0],
-               &interface_vtable,
-               NULL, NULL, &error);
-       if (reg_id == 0) {
-               LOGE("g_dbus_connection_register_object error(%s)", error->message);
-               g_error_free(error);
-       }
 }
 
 static void __on_bus_name_owner_changed(GDBusConnection  *connection,
@@ -813,6 +800,8 @@ bool _initialize_dbus(void)
        GError *error = NULL;
        guint subsc_id;
        guint owner_id;
+       guint reg_id;
+
        LOGD("__initialize_dbus Enter");
 
        connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
@@ -843,10 +832,21 @@ bool _initialize_dbus(void)
                return false;
        }
 
+       reg_id = g_dbus_connection_register_object(connection,
+                       ALARM_MGR_DBUS_PATH,
+                       introspection_data->interfaces[0],
+                       &interface_vtable,
+                       NULL, NULL, &error);
+       if (reg_id == 0) {
+               LOGE("g_dbus_connection_register_object error(%s)", error->message);
+               g_dbus_node_info_unref(introspection_data);
+               g_object_unref(connection);
+               g_error_free(error);
+       }
+
        owner_id = g_bus_own_name_on_connection(connection,
                        ALARM_MGR_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE,
                        __on_bus_name_acquired, NULL, NULL, NULL);
-
        if (owner_id == 0) {
                LOGE("Acquiring the own name is failed.");
                g_dbus_node_info_unref(introspection_data);