Fix: glib error
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-audio.c
index 524a5d2..3b32b20 100644 (file)
 #include "bt-service-headset-connection.h"
 
 #ifdef TIZEN_SUPPORT_DUAL_HF
+#ifdef TIZEN_PROFILE_WEARABLE
 #define VCONF_KEY_BT_HOST_BT_MAC_ADDR "db/wms/host_bt_mac"
 #endif
+#endif
 
 typedef struct {
        unsigned int type;
@@ -332,27 +334,27 @@ gboolean _bt_is_headset_type_connected(int type, char *address)
 #ifdef TIZEN_SUPPORT_DUAL_HF
 gboolean __bt_is_companion_device(const char *addr)
 {
-       if (TIZEN_PROFILE_WEARABLE) {
-               char *host_device_address = NULL;
-               host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
-
-               if (!host_device_address) {
-                       BT_INFO("Failed to get a companion device address");
-                       return FALSE;
-               }
+#ifdef TIZEN_PROFILE_WEARABLE
+       char *host_device_address = NULL;
+       host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
 
-               if (g_strcmp0(host_device_address, addr) == 0) {
-                       BT_INFO("Found companion device");
-                       free(host_device_address);
-                       return TRUE;
-               }
+       if (!host_device_address) {
+               BT_INFO("Failed to get a companion device address");
+               return FALSE;
+       }
 
+       if (g_strcmp0(host_device_address, addr) == 0) {
+               BT_INFO("Found companion device");
                free(host_device_address);
-               return FALSE;
-       } else {
-               /* TODO : Need to add companion device check condition for Phone models */
-               return FALSE;
+               return TRUE;
        }
+
+       free(host_device_address);
+       return FALSE;
+#else
+       /* TODO : Need to add companion device check condition for Phone models */
+       return FALSE;
+#endif
 }
 #endif
 
@@ -511,6 +513,12 @@ void _bt_add_headset_to_list(int type, int status, const char *address)
        }
 
        connected_device = g_malloc0(sizeof(bt_connected_headset_data_t));
+       /* Fix : NULL_RETURNS */
+       if (connected_device == NULL) {
+               BT_ERR("No memory allocated");
+               return;
+       }
+
        connected_device->device_state = status;
        if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING))
                connected_device->type |= type;
@@ -689,6 +697,12 @@ int _bt_audio_connect(int request_id, int type,
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        func_data = g_malloc0(sizeof(bt_audio_function_data_t));
+       /* Fix : NULL_RETURNS */
+       if (func_data == NULL) {
+               result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto fail;
+       }
+
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        func_data->type = type;
@@ -828,6 +842,12 @@ int _bt_audio_disconnect(int request_id, int type,
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        func_data = g_malloc0(sizeof(bt_audio_function_data_t));
+       /* Fix : NULL_RETURNS */
+       if (func_data == NULL) {
+               BT_ERR("Memory allocation error");
+               result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto fail;
+       }
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        func_data->pending = BT_PENDING_NONE;
@@ -968,6 +988,12 @@ int _bt_hf_connect(int request_id,
        }
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
+       /* Fix : NULL_RETURNS */
+       if (func_data == NULL) {
+               result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto fail;
+       }
+
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        uuid = g_strdup(HFP_AG_UUID);
@@ -1027,6 +1053,12 @@ int _bt_hf_disconnect(int request_id,
        }
 
        func_data = g_malloc0(sizeof(bt_function_data_t));
+       /* Fix : NULL_RETURNS */
+       if (func_data == NULL) {
+               result = BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+               goto fail;
+       }
+
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        uuid = g_strdup(HFP_AG_UUID);