mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-10 06:40:23 +00:00
replace malloc+memset by calloc
This commit is contained in:
parent
40d883bd01
commit
a32d71b603
@ -399,9 +399,8 @@ 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 = malloc(sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
gatt_helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
if (!gatt_helper) return;
|
||||
memset(gatt_helper, 0, sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
gatt_helper->con_handle = handle;
|
||||
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) gatt_helper);
|
||||
}
|
||||
@ -419,9 +418,8 @@ 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 = malloc(sizeof(btstack_linked_list_connection_t));
|
||||
btstack_linked_list_connection_t * con = calloc(sizeof(btstack_linked_list_connection_t));
|
||||
if (!con) return;
|
||||
memset(con, 0, sizeof(btstack_linked_list_connection_t));
|
||||
con->connection = connection;
|
||||
btstack_linked_list_add(&gatt_helper->all_connections, (btstack_linked_item_t *)con);
|
||||
}
|
||||
@ -831,9 +829,8 @@ btstack_linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(conn
|
||||
|
||||
if (!helper){
|
||||
log_info("helper does not exist");
|
||||
helper = malloc(sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
helper = calloc(sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
if (!helper) return NULL;
|
||||
memset(helper, 0, sizeof(btstack_linked_list_gatt_client_helper_t));
|
||||
helper->con_handle = con_handle;
|
||||
btstack_linked_list_add(&gatt_client_helpers, (btstack_linked_item_t *) helper);
|
||||
}
|
||||
@ -1326,9 +1323,8 @@ 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 = malloc(sizeof(client_state_t));
|
||||
client = calloc(sizeof(client_state_t));
|
||||
if (!client) break; // fail
|
||||
memset(client, 0, sizeof(client_state_t));
|
||||
client->connection = connection;
|
||||
client->power_mode = HCI_POWER_OFF;
|
||||
client->discoverable = 0;
|
||||
|
@ -309,9 +309,8 @@ 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 = malloc( sizeof(btstack_data_source_t));
|
||||
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
|
||||
if (ds == NULL) return -1;
|
||||
memset(ds, 0, sizeof(btstack_data_source_t));
|
||||
|
||||
// create tcp socket
|
||||
int fd = socket (PF_INET, SOCK_STREAM, 0);
|
||||
@ -367,9 +366,8 @@ 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 = malloc( sizeof(btstack_data_source_t));
|
||||
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
|
||||
if (ds == NULL) return;
|
||||
memset(ds, 0, sizeof(btstack_data_source_t));
|
||||
btstack_run_loop_set_data_source_fd(ds, listening_fd);
|
||||
btstack_run_loop_set_data_source_handler(ds, &socket_connection_accept);
|
||||
btstack_run_loop_enable_data_source_callbacks(ds, DATA_SOURCE_CALLBACK_READ);
|
||||
@ -455,9 +453,8 @@ int socket_connection_create_launchd(void){
|
||||
int socket_connection_create_unix(char *path){
|
||||
|
||||
// create btstack_data_source_t
|
||||
btstack_data_source_t *ds = malloc( sizeof(btstack_data_source_t));
|
||||
btstack_data_source_t *ds = calloc(sizeof(btstack_data_source_t));
|
||||
if (ds == NULL) return -1;
|
||||
memset(ds, 0, sizeof(btstack_data_source_t));
|
||||
|
||||
// create unix socket
|
||||
int fd = socket (AF_UNIX, SOCK_STREAM, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user