Code cleanup
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-common.c
index 792ca88..0f664f6 100644 (file)
@@ -83,6 +83,7 @@ GDBusConnection *g_bus_get_private_conn(void)
                                NULL, /* GDBusAuthObserver */
                                NULL,
                                &error);
+       g_free(address);
        if (!private_gconn) {
                if (error) {
                        BT_ERR("Unable to connect to dbus: %s", error->message);
@@ -1509,13 +1510,13 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid)
        proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL,
                                BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
                                &err);
-
        g_free(object_path);
-
-       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-       if (err) {
-               BT_ERR("DBus Error: [%s]", err->message);
-               g_clear_error(&err);
+       if (proxy == NULL) {
+               if (err) {
+                       BT_ERR("DBus Error: [%s]", err->message);
+                       g_clear_error(&err);
+               }
+               return BLUETOOTH_ERROR_INTERNAL;
        }
        ret = g_dbus_proxy_call_sync(proxy, "Get",
                        g_variant_new("(ss)", BT_DEVICE_INTERFACE, "UUIDs"),
@@ -1569,24 +1570,24 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class)
        GVariant *value = NULL;
        GVariant *result = NULL;
        unsigned int  class = 0x00;
-       int ret = BLUETOOTH_ERROR_INTERNAL;
+       int ret = BLUETOOTH_ERROR_NONE;
 
        gconn = __get_gdbus_connection();
        retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL);
-               object_path = _bt_get_device_object_path(address);
 
+       object_path = _bt_get_device_object_path(address);
        retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL,
                                BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL,
                                &err);
-
-       g_free(object_path);
-
-       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-       if (err) {
-               BT_ERR("DBus Error: [%s]", err->message);
-               g_clear_error(&err);
+       if (proxy == NULL) {
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (err) {
+                       BT_ERR("DBus Error: [%s]", err->message);
+                       g_clear_error(&err);
+               }
+               goto done;
        }
 
        result = g_dbus_proxy_call_sync(proxy, "Get",
@@ -1606,6 +1607,7 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class)
        }
 
 done:
+       g_free(object_path);
        if (proxy)
                g_object_unref(proxy);