Fix memory leak and remove dead code 33/173233/1 accepted/tizen/unified/20180322.060141 submit/tizen/20180320.233756
authorWootak Jung <wootak.jung@samsung.com>
Tue, 20 Mar 2018 06:06:34 +0000 (15:06 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Tue, 20 Mar 2018 06:06:34 +0000 (15:06 +0900)
Change-Id: Ib7e0abe1154008587a6c5eba34ff1d317e8653b4

src/bluetooth-common.c

index 6fb1bfb..f579673 100644 (file)
@@ -1253,6 +1253,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
                        (_bt_get_error_code(param->result), BT_AUTH_KEYBOARD_PASSKEY_DISPLAY, auth_information->device_name.name,
                                device_addr, auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_PIN_REQUEST:
                BT_INFO("bt_adapter_authentication_req_cb() will be called with \
@@ -1266,6 +1269,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
                        (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
                                auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_PASSKEY_REQUEST:
                BT_INFO("bt_adapter_authentication_req_cb will be called with \
@@ -1280,6 +1286,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
                        (_bt_get_error_code(param->result), BT_AUTH_PIN_REQUEST, auth_information->device_name.name, device_addr,
                                auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
                BT_INFO("bt_adapter_authentication_req_cb will be called with \
@@ -1293,6 +1302,9 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_adapter_authentication_req_cb)bt_event_slot_container[event_index].callback)
                        (_bt_get_error_code(param->result), BT_AUTH_PASSKEY_CONFIRM_REQUEST, auth_information->device_name.name, device_addr,
                                auth_information->str_passkey, bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_DEVICE_AUTHORIZED:
                BT_INFO("bt_device_authorization_changed_cb() will be called with BT_DEVICE_AUTHORIZED");
@@ -1582,9 +1594,6 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_map_client_list_folders_cb)bt_event_slot_container[event_index].callback)
                                                        (param->result, folders_struct->names, folders_struct->size,
                                                                        bt_event_slot_container[event_index].user_data);
-
-               if (device_addr != NULL)
-                       free(device_addr);
                break;
 
        case BLUETOOTH_EVENT_MAP_LIST_FILTER_FIELD_COMPLETE:
@@ -1595,9 +1604,6 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                        ((bt_map_client_list_filter_fields_cb)bt_event_slot_container[event_index].callback)
                                                        (param->result, fields_info->fields, fields_info->size,
                                                        bt_event_slot_container[event_index].user_data);
-
-                       if (device_addr != NULL)
-                               free(device_addr);
                }
                break;
 
@@ -1999,7 +2005,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
                (_bt_get_error_code(param->result), TRUE, device_addr, bt_event_slot_container[event_index].user_data);
 
-               g_free(device_addr);
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_HID_DEVICE_DISCONNECTED:
                BT_INFO("BLUETOOTH_HID_DEVICE_DISCONNECTED");
@@ -2008,7 +2015,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                ((bt_hid_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
                (_bt_get_error_code(param->result), FALSE, device_addr, bt_event_slot_container[event_index].user_data);
 
-               g_free(device_addr);
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_HID_DEVICE_DATA_RECEIVED:
                BT_INFO("HID Device Data");
@@ -2044,7 +2052,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                /* OTP Client */
                _bt_otp_client_connection_state_changed(param->result, device_addr, TRUE);
 
-               g_free(device_addr);
+               if (device_addr != NULL)
+                       free(device_addr);
                device_addr = NULL;
                break;
        }
@@ -2074,7 +2083,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                /* OTP Client */
                _bt_otp_client_connection_state_changed(param->result, device_addr, FALSE);
 
-               g_free(device_addr);
+               if (device_addr != NULL)
+                       free(device_addr);
                device_addr = NULL;
                break;
        }
@@ -2192,6 +2202,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                                                        BLUETOOTH_ERROR_INTERNAL, NULL, 0);
 
                        BT_INFO("GATT Server: Internal response sent for Read Request");
+                       if (device_addr != NULL)
+                               free(device_addr);
                        return;
                }
 
@@ -2464,7 +2476,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                _bt_otp_check_service_changed(device_addr, service_change);
 
                client = _bt_gatt_get_client(device_addr);
-               g_free(device_addr);
+               if (device_addr != NULL)
+                       free(device_addr);
                device_addr = NULL;
 
                if (client == NULL) {
@@ -2577,17 +2590,25 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                BT_INFO("BLUETOOTH_EVENT_IPSP_CONNECTED");
                bt_ipsp_iface_info = (bt_ipsp_connection_info_t *)(param->param_data);
                _bt_convert_address_to_string(&device_addr, &bt_ipsp_iface_info->btaddr);
+
                ((bt_ipsp_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
                (_bt_get_error_code(param->result), TRUE, device_addr, bt_ipsp_iface_info->if_name,
                 bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_IPSP_DISCONNECTED:
                BT_INFO("BLUETOOTH_EVENT_IPSP_DISCONNECTED");
                bt_ipsp_iface_info = (bt_ipsp_connection_info_t *)(param->param_data);
                _bt_convert_address_to_string(&device_addr, &bt_ipsp_iface_info->btaddr);
+
                ((bt_ipsp_connection_state_changed_cb)bt_event_slot_container[event_index].callback)
                (_bt_get_error_code(param->result), FALSE, device_addr, bt_ipsp_iface_info->if_name,
                 bt_event_slot_container[event_index].user_data);
+
+               if (device_addr != NULL)
+                       free(device_addr);
                break;
        case BLUETOOTH_EVENT_GATT_ATT_MTU_CHANGED: {
                bt_gatt_client_att_mtu_info_s *mtu_info = NULL;