Fix unwanted check logic before g_free() 73/134273/4
authorSyam Sidhardhan <s.syam@samsung.com>
Thu, 15 Jun 2017 15:13:25 +0000 (20:43 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Mon, 19 Jun 2017 08:11:54 +0000 (08:11 +0000)
g_free() internally validate the pointer

Change-Id: I7eb07198c65e79dfb9282445fd8625651fc120fc
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
src/bluetooth-adapter.c
src/bluetooth-audio.c
src/bluetooth-tds.c
test/bt_unit_test.c

index 4abca1b..b9ee131 100644 (file)
@@ -3297,8 +3297,7 @@ int bt_adapter_le_free_ibeacon_report(bt_adapter_le_ibeacon_scan_result_info_s *
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(ibeacon_info); /* LCOV_EXCL_START */
 
-       if (ibeacon_info->uuid)
-               g_free(ibeacon_info->uuid);
+       g_free(ibeacon_info->uuid);
 
        g_free(ibeacon_info);
 
index 0df98ae..928c3be 100644 (file)
@@ -827,8 +827,7 @@ int bt_call_list_reset(bt_call_list_h list)
                        break;
                handle->list = g_list_remove(handle->list, call_status);
 
-               if (NULL != call_status->phone_number)
-                       g_free(call_status->phone_number);
+               g_free(call_status->phone_number);
 
                g_free(call_status);
        } while (1);
index 2db6e60..43242ef 100644 (file)
@@ -478,10 +478,8 @@ void _bt_tds_control_point_indication_response_update(const char *address, bluet
                        if ((seeker_s)->control_point_act_cb)
                                ((bt_tds_control_point_activation_indication_cb)((seeker_s)->control_point_act_cb))(result,
                                address, info->tds_data.data, info->tds_data.length, (seeker_s)->control_point_act_user_data);
-                       if (seeker_s->activation_data) {
-                               g_free(seeker_s->activation_data);
-                               seeker_s->activation_data = NULL;
-                       }
+                       g_free(seeker_s->activation_data);
+                       seeker_s->activation_data = NULL;
                }
        }
 }
@@ -505,10 +503,8 @@ void _bt_tds_control_point_activation_result_update(int result, const char *remo
                                if ((seeker_s)->control_point_act_cb)
                                        ((bt_tds_control_point_activation_indication_cb)((seeker_s)->control_point_act_cb))(BT_ERROR_OPERATION_FAILED,
                                        remote_address, NULL, 0, (seeker_s)->control_point_act_user_data);
-                               if (seeker_s->activation_data) {
-                                       g_free(seeker_s->activation_data);
-                                       seeker_s->activation_data = NULL;
-                               }
+                               g_free(seeker_s->activation_data);
+                               seeker_s->activation_data = NULL;
                                return;
                        } else
                                BT_DBG("TDS Activation request successfully accepted by Provider, wait for Indication");
@@ -540,10 +536,8 @@ void _bt_tds_control_point_enabled_update(int result, const char *remote_address
                                ((bt_tds_control_point_activation_indication_cb)((seeker_s)->control_point_act_cb))(BT_ERROR_OPERATION_FAILED,
                                remote_address, NULL, 0, (seeker_s)->control_point_act_user_data);
 
-                       if (seeker_s->activation_data) {
-                               g_free(seeker_s->activation_data);
-                               seeker_s->activation_data = NULL;
-                       }
+                       g_free(seeker_s->activation_data);
+                       seeker_s->activation_data = NULL;
                        return;
                } else {
                        BT_DBG("TDS Control Point enabled successfully!!");
@@ -648,30 +642,20 @@ int _bt_tds_parse_transport_blocks(bt_tds_transport_block_list_s **info,
 
 static void __bt_tds_reset_seeker_data(bt_tds_seeker_s *seeker)
 {
-       if ((seeker)->tds_control_point) {
-               g_free((seeker)->tds_control_point);
-               (seeker)->tds_control_point = NULL;
-       }
+       g_free((seeker)->tds_control_point);
+       (seeker)->tds_control_point = NULL;
 
-       if ((seeker)->tds_control_point_cccd) {
-               g_free((seeker)->tds_control_point_cccd);
-               (seeker)->tds_control_point_cccd = NULL;
-       }
+       g_free((seeker)->tds_control_point_cccd);
+       (seeker)->tds_control_point_cccd = NULL;
 
-       if ((seeker)->tds_user_data_desciptor) {
-               g_free((seeker)->tds_user_data_desciptor);
-               (seeker)->tds_user_data_desciptor = NULL;
-       }
+       g_free((seeker)->tds_user_data_desciptor);
+       (seeker)->tds_user_data_desciptor = NULL;
 
-       if ((seeker)->tds_service_handle) {
-               g_free((seeker)->tds_service_handle);
-               (seeker)->tds_service_handle = NULL;
-       }
+       g_free((seeker)->tds_service_handle);
+       (seeker)->tds_service_handle = NULL;
 
-       if ((seeker)->activation_data) {
-               g_free((seeker)->activation_data);
-               (seeker)->activation_data = NULL;
-       }
+       g_free((seeker)->activation_data);
+       (seeker)->activation_data = NULL;
 
        /* Reset CCCD */
        (seeker)->cccd_enabled = false;
@@ -823,12 +807,10 @@ static int __bt_update_tds_transport_data(bluetooth_device_address_t *address, b
                                        bluetooth_gatt_free_desc_property(&desc_property);
                                        goto fail;
                                }
-                               if ((seeker_s)->tds_control_point)
-                                       g_free((seeker_s)->tds_control_point);
+                               g_free((seeker_s)->tds_control_point);
                                (seeker_s)->tds_control_point = g_strdup(characteristic.handle);
 
-                               if ((seeker_s)->tds_control_point_cccd)
-                                       g_free((seeker_s)->tds_control_point_cccd);
+                               g_free((seeker_s)->tds_control_point_cccd);
                                (seeker_s)->tds_control_point_cccd = g_strdup(desc_property.handle);
 
                                BT_DBG("TDS Control point handle [%s]", (seeker_s)->tds_control_point);
@@ -861,8 +843,7 @@ static int __bt_update_tds_transport_data(bluetooth_device_address_t *address, b
 
                                                if (g_strstr_len(desc_property.uuid, -1, BT_TDS_USER_DATA_DESCRIPTOR)) {
                                                        BT_DBG("User data descriptor handle discovered");
-                                                       if ((seeker_s)->tds_user_data_desciptor)
-                                                               g_free((seeker_s)->tds_user_data_desciptor);
+                                                       g_free((seeker_s)->tds_user_data_desciptor);
                                                        (seeker_s)->tds_user_data_desciptor = g_strdup(desc_property.handle);
                                                }
 
@@ -876,8 +857,7 @@ static int __bt_update_tds_transport_data(bluetooth_device_address_t *address, b
                bluetooth_gatt_free_char_property(&characteristic);
        } /* Next Charatceristic */
 
-       if ((seeker_s)->tds_service_handle)
-               g_free((seeker_s)->tds_service_handle);
+       g_free((seeker_s)->tds_service_handle);
 
        (seeker_s)->tds_service_handle = g_strdup(service.handle);
        bluetooth_gatt_free_service_property(&service);
index f39614c..ae59b3a 100644 (file)
@@ -2667,8 +2667,7 @@ void __tds_activation_req_cb(char *rem_bd_addr,
        for (i = 0; i < len; i++)
                TC_PRT("Act req data[%d] : %.2x", i, buf[i]);
 
-       if (tds_act_address)
-               g_free(tds_act_address);
+       g_free(tds_act_address);
        tds_act_address = g_strdup(rem_bd_addr);
 }