(fix bug) free handle regardless of dbus connection
authorsung.goo.kim <sung.goo.kim@samsung.com>
Tue, 20 Oct 2015 05:43:22 +0000 (14:43 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 5 Nov 2015 00:49:38 +0000 (09:49 +0900)
Change-Id: I6337388365259a682c4cbc042b6f4404bef315e9

lib/icl-presence.c
lib/icl-resource.c

index 5dba296..5345cd8 100644 (file)
@@ -209,15 +209,19 @@ API int iotcon_unsubscribe_presence(iotcon_presence_h presence)
        int ret;
        GError *error = NULL;
 
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
 
-       if (0 == presence->id) {
+       if (0 == presence->id) { /* disconnected iotcon dbus */
                WARN("Invalid Presence handle");
                free(presence);
                return IOTCON_ERROR_NONE;
        }
 
+       if (NULL == icl_dbus_get_object()) {
+               ERR("icl_dbus_get_object() return NULL");
+               return IOTCON_ERROR_DBUS;
+       }
+
        ic_dbus_call_unsubscribe_presence_sync(icl_dbus_get_object(), presence->handle,
                        &ret, NULL, &error);
        if (error) {
index bae3ae4..2efa040 100644 (file)
@@ -243,10 +243,9 @@ API int iotcon_resource_destroy(iotcon_resource_h resource)
        int ret;
        GError *error = NULL;
 
-       RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
 
-       if (0 == resource->sub_id) {
+       if (0 == resource->handle) { /* iotcon dbus disconnected */
                WARN("Invalid Resource handle");
                iotcon_resource_types_destroy(resource->types);
                if (resource->observers)
@@ -256,6 +255,11 @@ API int iotcon_resource_destroy(iotcon_resource_h resource)
                return IOTCON_ERROR_NONE;
        }
 
+       if (NULL == icl_dbus_get_object()) {
+               ERR("icl_dbus_get_object() return NULL");
+               return IOTCON_ERROR_DBUS;
+       }
+
        ic_dbus_call_unregister_resource_sync(icl_dbus_get_object(), resource->handle, NULL,
                        &error);
        if (error) {
@@ -264,9 +268,7 @@ API int iotcon_resource_destroy(iotcon_resource_h resource)
                g_error_free(error);
                return ret;
        }
-
        resource->handle = 0;
-
        icl_dbus_unsubscribe_signal(resource->sub_id);
 
        return IOTCON_ERROR_NONE;