From: Deokhyun Kim Date: Thu, 10 Jan 2019 05:04:31 +0000 (+0900) Subject: Fix svace issue(40981) X-Git-Tag: accepted/tizen/unified/20190115.055940~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ac850d06cff112e991186e3cda7bbf6dae65fd7;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Fix svace issue(40981) Change-Id: I2fa8b274e275a8aa949c274016b2ba8cfa6c7acb Signed-off-by: Deokhyun Kim --- diff --git a/bt-api/bt-hid-device.c b/bt-api/bt-hid-device.c index 3c3cbdd..50d04e0 100644 --- a/bt-api/bt-hid-device.c +++ b/bt-api/bt-hid-device.c @@ -303,18 +303,16 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, BT_INFO("TRANS HANDSHAKE"); recv_data.type = HTYPE_TRANS_HANDSHAKE; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; case BT_HID_TRANS_HID_CONTROL: BT_INFO("HID CONTROL"); recv_data.type = HTYPE_TRANS_HID_CONTROL; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; case BT_HID_TRANS_DATA: @@ -324,16 +322,14 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, BT_INFO("Input Report"); recv_data.param = PTYPE_DATA_RTYPE_INPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); } else { BT_INFO("Out Report"); recv_data.param = PTYPE_DATA_RTYPE_OUTPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); } break; @@ -348,9 +344,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.param = PTYPE_DATA_RTYPE_OUTPUT; } recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } @@ -365,9 +360,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.param = PTYPE_DATA_RTYPE_OUTPUT; } recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } @@ -376,9 +370,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.type = HTYPE_TRANS_GET_PROTOCOL; recv_data.param = PTYPE_DATA_RTYPE_INPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } @@ -387,9 +380,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.type = HTYPE_TRANS_SET_PROTOCOL; recv_data.param = PTYPE_DATA_RTYPE_INPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } @@ -398,9 +390,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.type = HTYPE_TRANS_GET_IDLE; recv_data.param = PTYPE_DATA_RTYPE_INPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } @@ -409,9 +400,8 @@ static gboolean __received_cb(GIOChannel *chan, GIOCondition cond, recv_data.type = HTYPE_TRANS_SET_IDLE; recv_data.param = PTYPE_DATA_RTYPE_INPUT; recv_data.buffer_size = len; - recv_data.buffer = (char *) malloc(sizeof(char) * len); - if (recv_data.buffer) - memcpy(recv_data.buffer, buffer, len); + recv_data.buffer = (char *)g_malloc0(sizeof(char) * len); + memcpy(recv_data.buffer, buffer, len); break; } diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index ab7eb04..4179595 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -464,13 +464,9 @@ static int close_bluetooth(struct hw_device_t *device) static int open_bluetooth(const struct hw_module_t *module, char const *name, struct hw_device_t **device) { - bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t)); + bluetooth_device_t *dev = g_malloc0(sizeof(bluetooth_device_t)); DBG(""); - if (!dev) { - ERR("dev is NULL"); - return 0; - } memset(dev, 0, sizeof(bluetooth_device_t)); dev->common.tag = HARDWARE_DEVICE_TAG; diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c index cc5b5b8..6f3daca 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-client.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-client.c @@ -248,11 +248,6 @@ static hal_gatt_client_app *__hal_gattc_add_client_app(bt_uuid_t *app_uuid) //add client app gattc_app = g_malloc0(sizeof(hal_gatt_client_app)); - if (gattc_app == NULL) { - DBG("Failed to allocate memory"); - return NULL; - } - gattc_app->client_if = __hal_generate_client_id(); memcpy(&gattc_app->app_uuid, app_uuid, sizeof(bt_uuid_t)); @@ -276,11 +271,6 @@ static bt_status_t __hal_gattc_register_client_app(bt_uuid_t *app_uuid) /*send event */ client_app_info = g_malloc0(sizeof(hal_gatt_client_app)); - if (NULL == client_app_info) { - ERR("Failed to allocate memory"); - return BT_STATUS_FAIL; - } - client_app_info->client_if = gattc_app->client_if; memcpy(&client_app_info->app_uuid, app_uuid, sizeof(bt_uuid_t)); g_idle_add(__bt_hal_register_client_cb, (gpointer)client_app_info); @@ -476,12 +466,6 @@ bt_status_t _hal_gattc_disconnect(int client_if, const bt_bdaddr_t *bd_addr, } gattc_data = g_malloc0(sizeof(hal_gattc_client_info_t)); - if (NULL == gattc_data) { - ERR("Unable to allocate memory"); - ret = BT_STATUS_FAIL; - goto fail; - } - memcpy(gattc_data->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX); gattc_data->client_if = client_if; @@ -1498,11 +1482,6 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t } resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } - resp_data->conn_id = conn_id; memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t)); @@ -1779,11 +1758,6 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t } resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } - resp_data->conn_id = conn_id; memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t)); @@ -2104,11 +2078,6 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv } resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } - resp_data->conn_id = conn_id; memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t)); @@ -2289,11 +2258,6 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr } resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } - resp_data->conn_id = conn_id; memcpy(&resp_data->srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); memcpy(&resp_data->char_id, char_id, sizeof(btgatt_gatt_id_t)); @@ -2448,11 +2412,7 @@ static bt_status_t _hal_register_for_notification(int client_if, return BT_STATUS_FAIL; } - resp_data = malloc(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } + resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); DBG("#StartNotify"); g_dbus_connection_call_sync(g_conn, @@ -2613,11 +2573,7 @@ static bt_status_t _hal_deregister_for_notification(int client_if, return BT_STATUS_FAIL; } - resp_data = malloc(sizeof(hal_gatt_resp_data_t)); - if (NULL == resp_data) { - ERR("failed to get the memory"); - return BT_STATUS_FAIL; - } + resp_data = g_malloc0(sizeof(hal_gatt_resp_data_t)); DBG("#StartNotify"); g_dbus_connection_call_sync(g_conn, @@ -3021,11 +2977,6 @@ static bt_status_t __bt_connect_le_device_internal(int client_if, const bt_bdadd } gattc_data = g_malloc0(sizeof(hal_gattc_client_info_t)); - if (gattc_data == NULL) { - ERR("Unable to allocate memory"); - ret = BT_STATUS_NOMEM; - goto fail; - } memcpy(gattc_data->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX); @@ -3159,11 +3110,6 @@ static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res, /*add gatt server connection info*/ gatt_conn_info = g_malloc0(sizeof(hal_gattc_server_info_t)); - if (gatt_conn_info == NULL) { - ERR("Failed to allocate memory"); - goto fail; - } - memcpy(gatt_conn_info->bd_addr.address, gattc_data->bd_addr.address, BT_HAL_ADDRESS_LENGTH_MAX); gatt_conn_info->inst_id = gattc_data->inst_id; hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, gatt_conn_info);