replace malloc+memset by calloc

This commit is contained in:
Matthias Ringwald 2016-03-27 23:01:37 +02:00
parent a32d71b603
commit af0d0df5e5
3 changed files with 8 additions and 9 deletions

View File

@ -399,7 +399,7 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
// if gatt_helper doesn't exist, create it and add it to gatt_client_helpers list
if (!gatt_helper){
gatt_helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t));
gatt_helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t), 1);
if (!gatt_helper) return;
gatt_helper->con_handle = handle;
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) gatt_helper);
@ -418,7 +418,7 @@ static void daemon_add_gatt_client_handle(connection_t * connection, uint32_t ha
// if connection is not found, add it to the all_connections, and set it as active connection
if (!connection_found){
btstack_linked_list_connection_t * con = calloc(sizeof(btstack_linked_list_connection_t));
btstack_linked_list_connection_t * con = calloc(sizeof(btstack_linked_list_connection_t), 1);
if (!con) return;
con->connection = connection;
btstack_linked_list_add(&gatt_helper->all_connections, (btstack_linked_item_t *)con);
@ -829,7 +829,7 @@ btstack_linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(conn
if (!helper){
log_info("helper does not exist");
helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t));
helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t), 1);
if (!helper) return NULL;
helper->con_handle = con_handle;
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) helper);
@ -1323,7 +1323,7 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
case DAEMON_EVENT_CONNECTION_OPENED:
log_info("DAEMON_EVENT_CONNECTION_OPENED %p\n",connection);
client = calloc(sizeof(client_state_t));
client = calloc(sizeof(client_state_t), 1);
if (!client) break; // fail
client->connection = connection;
client->power_mode = HCI_POWER_OFF;

View File

@ -309,7 +309,7 @@ static void socket_connection_accept(btstack_data_source_t *socket_ds, btstack_d
int socket_connection_create_tcp(int port){
// create btstack_data_source_t
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t), 1);
if (ds == NULL) return -1;
// create tcp socket
@ -366,7 +366,7 @@ void socket_connection_launchd_register_fd_array(launch_data_t listening_fd_arra
log_info("file descriptor = %u", listening_fd);
// create btstack_data_source_t for fd
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t), 1);
if (ds == NULL) return;
btstack_run_loop_set_data_source_fd(ds, listening_fd);
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
@ -453,7 +453,7 @@ int socket_connection_create_launchd(void){
int socket_connection_create_unix(char *path){
// create btstack_data_source_t
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t), 1);
if (ds == NULL) return -1;
// create unix socket

View File

@ -222,9 +222,8 @@ static int h4_open(void)
hci_transport_h4->uart_fd = fd;
// set up data_source
hci_transport_h4->ds = malloc(sizeof(btstack_data_source_t));
hci_transport_h4->ds = calloc(sizeof(btstack_data_source_t), 1);
if (!hci_transport_h4->ds) return -1;
memset(hci_transport_h4->ds, 0, sizeof(btstack_data_source_t));
btstack_run_loop_set_data_source_fd(hci_transport_h4->ds, fd);
btstack_run_loop_set_data_source_handler(hci_transport_h4->ds, &h4_process);
btstack_run_loop_enable_data_source_callbacks(hci_transport_h4->ds, DATA_SOURCE_CALLBACK_READ);