Fix g_object_unref assertions
authorJinWang An <jinwang.an@samsung.com>
Tue, 9 Apr 2019 01:01:55 +0000 (10:01 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:41 +0000 (17:53 +0900)
supervisor/mdss_ClientManager.cpp
supervisor/mdss_ClientManager.h

index 3207a97..a055845 100644 (file)
@@ -22,7 +22,6 @@ void ClientManager::onBusAcquired(GDBusConnection *conn, const gchar *name, gpoi
        ClientManager *ctx = (ClientManager*)userData;
        GError *error = NULL;
        RET_IF(NULL == ctx);
-       RET_IF(NULL == ctx->connection);
        RET_IF(NULL == ctx->dbusHandle);
 
        ctx->sigHandleChangeMode = g_signal_connect(ctx->dbusHandle, "handle-change-mode",
@@ -30,7 +29,7 @@ void ClientManager::onBusAcquired(GDBusConnection *conn, const gchar *name, gpoi
                        (gpointer)ctx);
 
        g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(ctx->dbusHandle),
-                       ctx->connection, MODES_DBUS_OBJPATH, &error);
+                       conn, MODES_DBUS_OBJPATH, &error);
 
        if (error) {
                ERR("Fail to g_dbus_interface_skeleton_export : %s", error->message);
@@ -41,23 +40,15 @@ void ClientManager::onBusAcquired(GDBusConnection *conn, const gchar *name, gpoi
 
 ClientManager::ClientManager(ModeManager *inModeManager)
 {
-       GError *error = NULL;
-
-       ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM, MODES_DBUS_INTERFACE,
-                       G_BUS_NAME_OWNER_FLAGS_REPLACE, ClientManager::onBusAcquired,
-                       NULL, NULL, this, NULL);
-       connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (NULL == connection) {
-               ERR("Can not get connection: %s", error? error->message : "unknown");
-               if (error) g_error_free(error);
-       }
-
        dbusHandle = mds_dbus_skeleton_new();
        if (NULL == dbusHandle) {
                ERR("Can not get mds_bus_skeleton handle");
        }
 
-       ownerId = 0;
+       ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM, MODES_DBUS_INTERFACE,
+                       G_BUS_NAME_OWNER_FLAGS_REPLACE, ClientManager::onBusAcquired,
+                       NULL, NULL, this, NULL);
+
        sigHandleChangeMode = 0;
        modeManager = inModeManager;
 }
@@ -68,36 +59,31 @@ ClientManager::~ClientManager()
        g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(dbusHandle));
        g_bus_unown_name(ownerId);
 
-       if (connection) g_object_unref(connection);
-       connection = NULL;
-
        if (dbusHandle) {
                g_object_unref(dbusHandle);
-               dbusHandle = NULL;
        }
 
        if (modeManager) {
                delete(modeManager);
-               modeManager = NULL;
        }
 }
 
-void ClientManager::changeModeHandler(mdsDbus*interface,
+gboolean ClientManager::changeModeHandler(mdsDbus *object,
                GDBusMethodInvocation *invocation,
-               const gchar *arg_mode_name, gpointer inUserData)
+               const gchar *arg_mode_name, gpointer userData)
 {
-       ClientManager *ctx = (ClientManager*)inUserData;
+       ClientManager *ctx = (ClientManager*)userData;
 
        DBG("change-mode method call received!");
        DBG("change-mode name %s", arg_mode_name? arg_mode_name : "NULL!!");
 
-       RET_IF(NULL == ctx);
+       RETV_IF(NULL == ctx, true);
 
        if (ctx->modeManager)
                ctx->modeManager->applyMode(arg_mode_name);
 
-       if (ctx->dbusHandle)
-               mds_dbus_complete_change_mode(ctx->dbusHandle,
-                               invocation, 0);
+       mds_dbus_complete_change_mode(object,
+                       invocation, 0);
+       return true;
 }
 
index 51c7e18..039bf92 100644 (file)
@@ -27,10 +27,9 @@ public:
 private:
        static void onBusAcquired(GDBusConnection *conn,
                        const gchar *name, gpointer user_data);
-       static void changeModeHandler(mdsDbus *interface,
+       static gboolean changeModeHandler(mdsDbus *object,
                        GDBusMethodInvocation *invocation,
-                       const gchar *arg_mode_name, gpointer user_data);
-       GDBusConnection *connection;
+                       const gchar *arg_mode_name, gpointer userData);
        mdsDbus *dbusHandle;
        guint ownerId;
        ModeManager *modeManager;