From: Syam Sidhardhan Date: Thu, 1 Jun 2017 06:42:41 +0000 (+0530) Subject: Fix invalid return check for g_malloc X-Git-Tag: submit/tizen_3.0/20171207.001107~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=651f032848a01fe2992c44decf653acf7bcf93e5;p=platform%2Fcore%2Fapi%2Fbluetooth.git Fix invalid return check for g_malloc g_malloc*() will always return a valid pointer, otherwise it will assert Change-Id: I578af7790e8f93ae2027a12f814ea314a73cab54 --- diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index de7e196..c8b216e 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -1547,11 +1547,6 @@ int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser) BT_CHECK_INPUT_PARAMETER(advertiser); __adv = (bt_advertiser_s *)g_malloc0(sizeof(bt_advertiser_s)); - if (__adv == NULL) { - BT_ERR("OUT_OF_MEMORY(0x%08x)", - BT_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ - return BT_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_LINE */ - } __adv->handle = GPOINTER_TO_INT(__adv); *advertiser = (bt_advertiser_h)__adv; @@ -1785,8 +1780,6 @@ static int __bt_convert_string_to_uuid(const char *string, unsigned short val; char *stop; data = g_malloc0(sizeof(char) *2); - if (data == NULL) - return BT_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_LINE */ val = strtol(string, &stop, 16); val = htons(val); @@ -1809,9 +1802,6 @@ static int __bt_convert_string_to_uuid(const char *string, unsigned int val0, val4; unsigned short val1, val2, val3, val5; data = g_malloc0(sizeof(char) *16); - /* Fix : NULL_RETURNS */ - if (data == NULL) - return BT_ERROR_OUT_OF_MEMORY; /* UUID format : %08x-%04hx-%04hx-%04hx-%08x%04hx */ strncpy(str_ptr, string, 36); @@ -1873,9 +1863,6 @@ static int __bt_convert_byte_ordering(char *data, int data_len, /* Convert to little endian */ swp = g_malloc0(data_len); - /* Fix : NULL_RETURNS */ - if (swp == NULL) - return BT_ERROR_OUT_OF_MEMORY; for (i = 0, j = data_len - 1; i < data_len; i++, j--) swp[i] = data[j]; @@ -1970,8 +1957,6 @@ static int __bt_append_adv_type_data(bt_advertiser_h advertiser, } new_adv = g_malloc0(adv_len + new_data_len); - if (!new_adv) - return BT_ERROR_OUT_OF_MEMORY; for (i = 0; i < adv_len; i++) { len = adv_data[i]; @@ -2148,10 +2133,6 @@ int bt_adapter_le_add_advertising_service_data(bt_advertiser_h advertiser, g_free(uuid_ptr); adv_data = g_malloc0(sizeof(char) *(service_data_len + 2)); - if (!adv_data) { - g_free(converted_uuid); /* LCOV_EXCL_LINE */ - return BT_ERROR_OUT_OF_MEMORY; - } memcpy(adv_data, converted_uuid, 2); memcpy(adv_data + 2, service_data, service_data_len); @@ -2213,8 +2194,6 @@ int bt_adapter_le_add_advertising_manufacturer_data(bt_advertiser_h advertiser, } adv_data = g_malloc0(sizeof(char) *(manufacturer_data_len + 2)); - if (!adv_data) - return BT_ERROR_OUT_OF_MEMORY; adv_data[0] = manufacturer_id & 0xffffffff; adv_data[1] = (manufacturer_id & 0xff00) >> 8; @@ -2874,9 +2853,6 @@ int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_ return BT_ERROR_NO_DATA; *uuids = g_malloc0(sizeof(char *) *uuid_count); - /* Fix : NULL_RETURNS */ - if (*uuids == NULL) - return BT_ERROR_OUT_OF_MEMORY; *count = uuid_count; @@ -2898,18 +2874,13 @@ int bt_adapter_le_get_scan_result_service_uuids(const bt_adapter_le_device_scan_ for (i = 0; i < (field_len - 1); i += uuid_size) { if (uuid_size == 2) { (*uuids)[uuid_index] = g_malloc0(sizeof(char) *4 + 1); - /* Fix : NULL_RETURNS */ - if ((*uuids)[uuid_index] == NULL) - return BT_ERROR_OUT_OF_MEMORY; snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); } else { (*uuids)[uuid_index] = g_malloc0(sizeof(char) *36 + 1); - /* Fix : NULL_RETURNS */ - if ((*uuids)[uuid_index] == NULL) - return BT_ERROR_OUT_OF_MEMORY; + snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], @@ -2955,9 +2926,6 @@ int bt_adapter_le_get_scan_result_device_name(const bt_adapter_le_device_scan_re if (adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_LOCAL_NAME || adv_data[1] == BT_ADAPTER_LE_ADVERTISING_DATA_SHORT_LOCAL_NAME) { *name = g_malloc0(sizeof(char) *field_len); - /* Fix : NULL_RETURNS */ - if (*name == NULL) - return BT_ERROR_OUT_OF_MEMORY; memcpy(*name, &adv_data[2], field_len - 1); return BT_ERROR_NONE; @@ -3062,9 +3030,6 @@ int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le return BT_ERROR_NO_DATA; *uuids = g_malloc0(sizeof(char *) *uuid_count); - /* Fix : NULL_RETURNS */ - if (*uuids == NULL) - return BT_ERROR_OUT_OF_MEMORY; *count = uuid_count; remain_data = adv_data; @@ -3083,17 +3048,11 @@ int bt_adapter_le_get_scan_result_service_solicitation_uuids(const bt_adapter_le for (i = 0; i < (field_len - 1); i += uuid_size) { if (uuid_size == 2) { (*uuids)[uuid_index] = g_malloc0(sizeof(char) *4 + 1); - /* Fix : NULL_RETURNS */ - if ((*uuids)[uuid_index] == NULL) - return BT_ERROR_OUT_OF_MEMORY; snprintf((*uuids)[uuid_index], 5, "%2.2X%2.2X", remain_data[i+3], remain_data[i+2]); } else { (*uuids)[uuid_index] = g_malloc0(sizeof(char) *36 + 1); - /* Fix : NULL_RETURNS */ - if ((*uuids)[uuid_index] == NULL) - return BT_ERROR_OUT_OF_MEMORY; snprintf((*uuids)[uuid_index], 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", remain_data[i+17], remain_data[i+16], remain_data[i+15], remain_data[i+14], remain_data[i+13], remain_data[i+12], remain_data[i+11], remain_data[i+10], remain_data[i+9], remain_data[i+8], @@ -3155,9 +3114,6 @@ int bt_adapter_le_get_scan_result_service_data_list(const bt_adapter_le_device_s return BT_ERROR_NO_DATA; *data_list = g_malloc0(sizeof(bt_adapter_le_service_data_s) *data_count); - /* Fix : NULL_RETURNS */ - if (*data_list == NULL) - return BT_ERROR_OUT_OF_MEMORY; *count = data_count; remain_data = adv_data; @@ -3333,18 +3289,12 @@ int bt_adapter_le_get_scan_result_ibeacon_report(const bt_adapter_le_device_scan return BT_ERROR_NO_DATA; *ibeacon_info = g_malloc0(sizeof(bt_adapter_ibeacon_scan_result_info_s)); - if (*ibeacon_info == NULL) - return BT_ERROR_OUT_OF_MEMORY; (*ibeacon_info)->company_id = manufacturer_id; (*ibeacon_info)->ibeacon_type = manufacturer_data[1] << 8; (*ibeacon_info)->ibeacon_type += manufacturer_data[0]; (*ibeacon_info)->uuid = g_malloc0(sizeof(char) *36 + 1); - if ((*ibeacon_info)->uuid == NULL) { - g_free(*ibeacon_info); - return BT_ERROR_OUT_OF_MEMORY; - } snprintf((*ibeacon_info)->uuid, 37, "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X", manufacturer_data[17], manufacturer_data[16], manufacturer_data[15], manufacturer_data[14], @@ -3373,11 +3323,6 @@ int bt_adapter_le_scan_filter_create(bt_scan_filter_h *scan_filter) BT_CHECK_INPUT_PARAMETER(scan_filter); __filter = (bt_le_scan_filter_s *)g_malloc0(sizeof(bt_le_scan_filter_s)); - if (__filter == NULL) { - BT_ERR("OUT_OF_MEMORY(0x%08x)", - BT_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ - return BT_ERROR_OUT_OF_MEMORY; - } __filter->manufacturer_id = -1; *scan_filter = (bt_scan_filter_h)__filter; diff --git a/src/bluetooth-audio.c b/src/bluetooth-audio.c index b11d6f2..e89db7b 100644 --- a/src/bluetooth-audio.c +++ b/src/bluetooth-audio.c @@ -776,10 +776,6 @@ int bt_call_list_create(bt_call_list_h *list) return BT_ERROR_ALREADY_DONE; } handle = g_malloc0(sizeof(call_list_s)); - if (handle == NULL) { - BT_ERR("BT_ERROR_OUT_OF_MEMORY(0x%08x)", BT_ERROR_OUT_OF_MEMORY); - return BT_ERROR_OUT_OF_MEMORY; - } *list = handle; return BT_ERROR_NONE; @@ -836,9 +832,6 @@ int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state handle = (call_list_s *)list; call_status = g_malloc0(sizeof(bt_telephony_call_status_info_t)); - /* Fix : NULL_RETURNS */ - if (call_status == NULL) - return BT_ERROR_OUT_OF_MEMORY; call_status->call_id = call_id; call_status->call_status = state; if (phone_number) diff --git a/src/bluetooth-avrcp.c b/src/bluetooth-avrcp.c index 6a73b44..5b1c965 100644 --- a/src/bluetooth-avrcp.c +++ b/src/bluetooth-avrcp.c @@ -573,16 +573,14 @@ int bt_avrcp_control_get_track_info(bt_avrcp_metadata_attributes_info_s **track) } else { tr_info = (bt_avrcp_metadata_attributes_info_s *)g_malloc0( sizeof(bt_avrcp_metadata_attributes_info_s)); - if (tr_info) { - tr_info->title = metadata.title; - tr_info->artist = metadata.artist; - tr_info->album = metadata.album; - tr_info->genre = metadata.genre; - tr_info->total_tracks = metadata.total_tracks; - tr_info->number = metadata.number; - tr_info->duration = metadata.duration; - *track = tr_info; - } + tr_info->title = metadata.title; + tr_info->artist = metadata.artist; + tr_info->album = metadata.album; + tr_info->genre = metadata.genre; + tr_info->total_tracks = metadata.total_tracks; + tr_info->number = metadata.number; + tr_info->duration = metadata.duration; + *track = tr_info; } return error; } diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index 5b7786b..f58d8b5 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -725,10 +725,6 @@ static int __bt_get_bt_device_sdp_info_s(bt_device_sdp_info_s **dest, bt_sdp_inf *dest = (bt_device_sdp_info_s *)g_malloc0(sizeof(bt_device_sdp_info_s)); - /* Fix : NULL_RETURNS */ - if (*dest == NULL) - return BT_ERROR_OUT_OF_MEMORY; - if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { __bt_free_bt_device_sdp_info_s(*dest); return BT_ERROR_OUT_OF_MEMORY; @@ -786,8 +782,6 @@ static void __bt_free_bt_device_sdp_info_s(bt_device_sdp_info_s *sdp_info) static int __bt_get_bt_device_att_mtu_info_s(bt_device_att_mtu_info_s **dest, bluetooth_le_att_mtu_info_t *source) { *dest = (bt_device_att_mtu_info_s *)g_malloc0(sizeof(bt_device_att_mtu_info_s)); - if (*dest == NULL) - return BT_ERROR_OUT_OF_MEMORY; if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_address)) != BT_ERROR_NONE) { g_free(*dest); @@ -806,10 +800,6 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de { *dest = (bt_device_connection_info_s *)g_malloc0(sizeof(bt_device_connection_info_s)); - /* Fix : NULL_RETURNS */ - if (*dest == NULL) - return BT_ERROR_OUT_OF_MEMORY; - if (_bt_convert_address_to_string(&((*dest)->remote_address), &(source->device_addr)) != BT_ERROR_NONE) { __bt_free_bt_device_connection_info_s(*dest); return BT_ERROR_OUT_OF_MEMORY; @@ -2614,8 +2604,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us if (device_addr != NULL) free(device_addr); - if (vcard_info != NULL) - free(vcard_info); + g_free(vcard_info); break; } @@ -2978,10 +2967,7 @@ static void __bt_le_event_proxy(int event, bluetooth_event_param_t *param, void } __bt_free_tds_scan_result_info_s(info); - if (data) { - g_free(data); - data = NULL; - } + g_free(data); } } diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 8f1fa1d..8c660f7 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -1394,22 +1394,13 @@ int bt_gatt_set_int_value(bt_gatt_h gatt_handle, bt_data_type_int_e type, *val_len = fmt_size; } else if (*val_len == offset) { /* Added */ tmp = g_malloc0(*val_len + fmt_size); - /* Fix : NULL_RETURNS */ - if (!tmp) { - g_free(*val); - return BT_ERROR_OUT_OF_MEMORY; - } + memcpy(tmp, *val, *val_len); g_free(*val); *val = tmp; *val_len += fmt_size; } else if (*val_len < offset + fmt_size) {/* Overlapped */ tmp = g_malloc0(offset + fmt_size); - /* Fix : NULL_RETURNS */ - if (!tmp) { - g_free(*val); - return BT_ERROR_OUT_OF_MEMORY; - } memcpy(tmp, *val, *val_len); g_free(*val); *val = tmp; @@ -1519,28 +1510,15 @@ int bt_gatt_set_float_value(bt_gatt_h gatt_handle, bt_data_type_float_e type, if (*val == NULL) { *val = g_malloc0(fmt_size); - /* Fix : NULL_RETURNS */ - if (*val == NULL) - return BT_ERROR_OUT_OF_MEMORY; *val_len = fmt_size; } else if (*val_len == offset) {/* Added */ tmp = g_malloc0(*val_len + fmt_size); - /* Fix : NULL_RETURNS */ - if (tmp == NULL) { - g_free(*val); - return BT_ERROR_OUT_OF_MEMORY; - } memcpy(tmp, *val, *val_len); g_free(*val); *val = tmp; *val_len += fmt_size; } else if (*val_len < offset + fmt_size) {/* Overlapped */ tmp = g_malloc0(offset + fmt_size); - /* Fix : NULL_RETURNS */ - if (tmp == NULL) { - g_free(*val); - return BT_ERROR_OUT_OF_MEMORY; - } memcpy(tmp, *val, *val_len); g_free(*val); *val = tmp;