Fix incorrect memory validation for g_malloc*()
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-device.c
index 61ec43a..b3ec8b5 100644 (file)
@@ -37,6 +37,7 @@
 #include "bt-service-network.h"
 #include "bt-service-adapter.h"
 #include "bt-service-gap-agent.h"
+#include "bt-service-pbap.h"
 
 #define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
 #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
@@ -317,7 +318,7 @@ static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
        ret_if(info == NULL);
 
        info->uuid_count = g_variant_get_size(value);
-       info->uuids = g_variant_dup_strv(value, &info->uuid_count);
+       info->uuids = g_variant_dup_strv(value, (gsize *)&info->uuid_count);
 }
 
 bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
@@ -558,12 +559,6 @@ static gboolean __ignore_auto_pairing_request(const char *address)
        }
 
        buffer = g_malloc0(sizeof(char) * size);
-       /* Fix : NULL_RETURNS */
-       if (buffer == NULL) {
-               BT_ERR("Memory allocation error\n");
-               fclose(fp);
-               return FALSE;
-       }
        result = fread((char *)buffer, 1, size, fp);
        fclose(fp);
        if (result != size) {
@@ -1141,12 +1136,6 @@ int _bt_unbond_device(int request_id,
 
        /* allocate user data so that it can be retrieved in callback */
        unbonding_info = g_malloc0(sizeof(bt_funcion_data_t));
-       /* Fix : NULL_RETURNS */
-       if (unbonding_info == NULL) {
-               BT_ERR("Memory not allocated !");
-               return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-       }
-
        unbonding_info->addr = g_malloc0(BT_ADDRESS_STRING_SIZE);
        unbonding_info->req_id = request_id;
 
@@ -1258,15 +1247,14 @@ static void __bt_discover_cb(GDBusProxy *proxy, GAsyncResult *res,
                g_dbus_error_strip_remote_error(err);
                BT_ERR("Error occured in Proxy call [%s]\n", err->message);
 
-               if (g_strrstr("Operation canceled", err->message)) {
+               if (g_strrstr("Operation canceled", err->message))
                        result = BLUETOOTH_ERROR_CANCEL_BY_USER;
-               } else if (g_strrstr("In Progress", err->message)) {
+               else if (g_strrstr("In Progress", err->message))
                        result = BLUETOOTH_ERROR_IN_PROGRESS;
-               } else if (g_strrstr("Host is down", err->message)) {
+               else if (g_strrstr("Host is down", err->message))
                        result = BLUETOOTH_ERROR_HOST_DOWN;
-               } else {
+               else
                        result = BLUETOOTH_ERROR_CONNECTION_ERROR;
-               }
 
                if (result == BLUETOOTH_ERROR_HOST_DOWN ||
                     result == BLUETOOTH_ERROR_CONNECTION_ERROR) {
@@ -1923,12 +1911,6 @@ static int __bt_connect_le_device_internal(int req_id, const bluetooth_device_ad
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
-       if (func_data == NULL) {
-               BT_ERR("Unable to allocate memory for address");
-               ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-               goto fail;
-       }
-
        func_data->address = g_strdup(device_address);
        if (func_data->address == NULL) {
                BT_ERR("Unable to allocate memory for address");
@@ -2041,12 +2023,6 @@ int _bt_disconnect_le_device(int req_id,
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
-       if (func_data == NULL) {
-               BT_ERR("Unable to allocate memory for address");
-               ret = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
-               goto fail;
-       }
-
        func_data->address = g_strdup(device_address);
        if (func_data->address == NULL) {
                BT_ERR("Unable to allocate memory for address");
@@ -2237,6 +2213,47 @@ int _bt_connect_profile(char *address, char *uuid,
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_disconnect_all(char *address)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       char *object_path;
+       GDBusProxy *proxy;
+       GDBusConnection *conn;
+       GVariant *result = NULL;
+       GError *err = NULL;
+
+       BT_DBG("");
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       object_path = _bt_get_device_object_path(address);
+       retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                                       NULL, BT_BLUEZ_NAME,
+                                       object_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+       g_free(object_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       result = g_dbus_proxy_call_sync(proxy, "Disconnect",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1, NULL,
+               &err);
+
+       if (err != NULL) {
+               BT_ERR("Dbus Call Error:[%s]", err->message);
+               g_error_free(err);
+               ret = BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       g_object_unref(proxy);
+       if (result)
+               g_variant_unref(result);
+
+       return ret;
+}
+
 int _bt_disconnect_profile(char *address, char *uuid,
                                                void *cb, gpointer func_data)
 {
@@ -2668,13 +2685,13 @@ char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
 
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
 {
-       if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0) {
+       if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0)
                return TRUSTED_PROFILE_PBAP;
-       } else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0) {
+       else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0)
                return TRUSTED_PROFILE_MAP;
-       } else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0) {
+       else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0)
                return TRUSTED_PROFILE_SAP;
-       }
+
        return 0; /* 0 - Unknown Profile */
 }
 
@@ -3204,11 +3221,10 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address,
 
        BT_DBG("ID Address:%s", idaddress);
 
-       if (idaddress) {
+       if (idaddress)
                _bt_convert_addr_string_to_type(id_address->addr, idaddress);
-       } else {
+       else
                ret = BLUETOOTH_ERROR_INTERNAL;
-       }
 
        g_object_unref(device_proxy);