Return ALREADY_CONNECT ERROR if device is already paired
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-hf-client.c
index 46f3faf..05dc62c 100644 (file)
@@ -172,16 +172,19 @@ void cb_hf_client_connection_state(bthf_client_connection_state_t state, unsigne
        int event_type;
        bdstr_t bdstr;
        bt_address_t * event_data = NULL;
-       event_data = g_new0(bt_address_t, 1);
-       memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
 
        if (bd_addr == NULL) {
                BT_ERR("Address is NULL");
-               if (event_data)
-                       g_free(event_data);
                return;
        }
 
+       event_data = g_new0(bt_address_t, 1);
+       if (event_data == NULL) {
+               BT_ERR("failed to allocate event_data");
+               return;
+       }
+       memcpy(event_data->addr, bd_addr->address, BT_ADDRESS_BYTES_NUM);
+
        BT_INFO("HFP Client Profile state = [%d],  BT Address = [%s]", state, bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
        switch (state) {
        case BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED: {
@@ -202,8 +205,7 @@ void cb_hf_client_connection_state(bthf_client_connection_state_t state, unsigne
        }
        default: {
                BT_INFO("Invalid state");
-               if (event_data)
-                       g_free(event_data);
+               g_free(event_data);
                return;
        }
        }