Fix unwanted check before g_free() 46/141946/1
authorSyam Sidhardhan <s.syam@samsung.com>
Fri, 2 Jun 2017 17:29:03 +0000 (22:59 +0530)
committerNagaraj D R <nagaraj.dr@samsung.com>
Wed, 2 Aug 2017 05:27:01 +0000 (10:57 +0530)
g_free() internally validate the pointer

Change-Id: I4309c581eeb1ec2b289c834f7a952348d73f287a

src/bluetooth-adapter.c
src/bluetooth-audio.c
src/bluetooth-tds.c
test/bt_unit_test.c

index 35c2f1c6851b5b0f21a952aeec10f4410705e757..de7e196c8cdf4d6b64d35b6cfa7131612fe16b83 100644 (file)
@@ -3303,8 +3303,7 @@ int bt_adapter_le_free_ibeacon_report(bt_adapter_ibeacon_scan_result_info_s *ibe
        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 f3d0e357114183b3f0c14253aa01765a77228253..b11d6f26d1f292e62e4ef13b7bba72b927f9bfdc 100644 (file)
@@ -816,8 +816,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 5a9a7e68ae2e634391f4f4b1d446fe1ed93ebfea..6cec83c35875830068dffb3d69ac7b4035770e88 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;
-                               }
                                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,35 +642,23 @@ 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)->remote_address) {
-               g_free((seeker)->remote_address);
-               (seeker)->remote_address = NULL;
-       }
+       g_free((seeker)->remote_address);
+       (seeker)->remote_address = NULL;
 
-       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;
@@ -828,12 +810,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);
@@ -866,8 +846,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);
                                                }
 
@@ -881,8 +860,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 0110e112eac47c9c5e08a4891f5b1cf6936b9ca3..c99271055c8994be89e1700c6a28bf033e504b55 100644 (file)
@@ -2670,8 +2670,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);
 }