mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 00:28:18 +00:00
btstack_memory: initialize all buffers on btstack_memory_TYPE_get()
This commit is contained in:
parent
64cb054c86
commit
a2673d8810
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- SM: prevent random address updates if gap_random_address_set was used
|
||||
- SM: fix internal buffer overrun that can cause storing of bonding information to fail
|
||||
- L2CAP: fix use after free on disconnect if ERTM is enabled
|
||||
- Memory Pools: clear all buffers before use
|
||||
|
||||
## Changes October 2018
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
* @brief BTstack memory management via configurable memory pools
|
||||
*
|
||||
* @note code generated by tool/btstack_memory_generator.py
|
||||
* @note returnes buffers are initialized with 0
|
||||
*
|
||||
*/
|
||||
|
||||
@ -66,7 +67,11 @@
|
||||
static hci_connection_t hci_connection_storage[MAX_NR_HCI_CONNECTIONS];
|
||||
static btstack_memory_pool_t hci_connection_pool;
|
||||
hci_connection_t * btstack_memory_hci_connection_get(void){
|
||||
return (hci_connection_t *) btstack_memory_pool_get(&hci_connection_pool);
|
||||
void * buffer = btstack_memory_pool_get(&hci_connection_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(hci_connection_t));
|
||||
}
|
||||
return (hci_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
||||
btstack_memory_pool_free(&hci_connection_pool, hci_connection);
|
||||
@ -82,7 +87,11 @@ void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
hci_connection_t * btstack_memory_hci_connection_get(void){
|
||||
return (hci_connection_t*) malloc(sizeof(hci_connection_t));
|
||||
void * buffer = malloc(sizeof(hci_connection_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(hci_connection_t));
|
||||
}
|
||||
return (hci_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
||||
free(hci_connection);
|
||||
@ -105,7 +114,11 @@ void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
||||
static l2cap_service_t l2cap_service_storage[MAX_NR_L2CAP_SERVICES];
|
||||
static btstack_memory_pool_t l2cap_service_pool;
|
||||
l2cap_service_t * btstack_memory_l2cap_service_get(void){
|
||||
return (l2cap_service_t *) btstack_memory_pool_get(&l2cap_service_pool);
|
||||
void * buffer = btstack_memory_pool_get(&l2cap_service_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(l2cap_service_t));
|
||||
}
|
||||
return (l2cap_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
||||
btstack_memory_pool_free(&l2cap_service_pool, l2cap_service);
|
||||
@ -121,7 +134,11 @@ void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
l2cap_service_t * btstack_memory_l2cap_service_get(void){
|
||||
return (l2cap_service_t*) malloc(sizeof(l2cap_service_t));
|
||||
void * buffer = malloc(sizeof(l2cap_service_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(l2cap_service_t));
|
||||
}
|
||||
return (l2cap_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
||||
free(l2cap_service);
|
||||
@ -143,7 +160,11 @@ void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
||||
static l2cap_channel_t l2cap_channel_storage[MAX_NR_L2CAP_CHANNELS];
|
||||
static btstack_memory_pool_t l2cap_channel_pool;
|
||||
l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
|
||||
return (l2cap_channel_t *) btstack_memory_pool_get(&l2cap_channel_pool);
|
||||
void * buffer = btstack_memory_pool_get(&l2cap_channel_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(l2cap_channel_t));
|
||||
}
|
||||
return (l2cap_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
||||
btstack_memory_pool_free(&l2cap_channel_pool, l2cap_channel);
|
||||
@ -159,7 +180,11 @@ void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
|
||||
return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t));
|
||||
void * buffer = malloc(sizeof(l2cap_channel_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(l2cap_channel_t));
|
||||
}
|
||||
return (l2cap_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
||||
free(l2cap_channel);
|
||||
@ -182,7 +207,11 @@ void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
||||
static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NR_RFCOMM_MULTIPLEXERS];
|
||||
static btstack_memory_pool_t rfcomm_multiplexer_pool;
|
||||
rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
|
||||
return (rfcomm_multiplexer_t *) btstack_memory_pool_get(&rfcomm_multiplexer_pool);
|
||||
void * buffer = btstack_memory_pool_get(&rfcomm_multiplexer_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
|
||||
}
|
||||
return (rfcomm_multiplexer_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
|
||||
btstack_memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
|
||||
@ -198,7 +227,11 @@ void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multipl
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
|
||||
return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t));
|
||||
void * buffer = malloc(sizeof(rfcomm_multiplexer_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_multiplexer_t));
|
||||
}
|
||||
return (rfcomm_multiplexer_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
|
||||
free(rfcomm_multiplexer);
|
||||
@ -220,7 +253,11 @@ void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multipl
|
||||
static rfcomm_service_t rfcomm_service_storage[MAX_NR_RFCOMM_SERVICES];
|
||||
static btstack_memory_pool_t rfcomm_service_pool;
|
||||
rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
|
||||
return (rfcomm_service_t *) btstack_memory_pool_get(&rfcomm_service_pool);
|
||||
void * buffer = btstack_memory_pool_get(&rfcomm_service_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_service_t));
|
||||
}
|
||||
return (rfcomm_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
||||
btstack_memory_pool_free(&rfcomm_service_pool, rfcomm_service);
|
||||
@ -236,7 +273,11 @@ void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
|
||||
return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t));
|
||||
void * buffer = malloc(sizeof(rfcomm_service_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_service_t));
|
||||
}
|
||||
return (rfcomm_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
||||
free(rfcomm_service);
|
||||
@ -258,7 +299,11 @@ void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
||||
static rfcomm_channel_t rfcomm_channel_storage[MAX_NR_RFCOMM_CHANNELS];
|
||||
static btstack_memory_pool_t rfcomm_channel_pool;
|
||||
rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
|
||||
return (rfcomm_channel_t *) btstack_memory_pool_get(&rfcomm_channel_pool);
|
||||
void * buffer = btstack_memory_pool_get(&rfcomm_channel_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_channel_t));
|
||||
}
|
||||
return (rfcomm_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
||||
btstack_memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
|
||||
@ -274,7 +319,11 @@ void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
|
||||
return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t));
|
||||
void * buffer = malloc(sizeof(rfcomm_channel_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(rfcomm_channel_t));
|
||||
}
|
||||
return (rfcomm_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
||||
free(rfcomm_channel);
|
||||
@ -297,7 +346,11 @@ void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
||||
static btstack_link_key_db_memory_entry_t btstack_link_key_db_memory_entry_storage[MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES];
|
||||
static btstack_memory_pool_t btstack_link_key_db_memory_entry_pool;
|
||||
btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
|
||||
return (btstack_link_key_db_memory_entry_t *) btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
|
||||
void * buffer = btstack_memory_pool_get(&btstack_link_key_db_memory_entry_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
|
||||
}
|
||||
return (btstack_link_key_db_memory_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
|
||||
btstack_memory_pool_free(&btstack_link_key_db_memory_entry_pool, btstack_link_key_db_memory_entry);
|
||||
@ -313,7 +366,11 @@ void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_me
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
btstack_link_key_db_memory_entry_t * btstack_memory_btstack_link_key_db_memory_entry_get(void){
|
||||
return (btstack_link_key_db_memory_entry_t*) malloc(sizeof(btstack_link_key_db_memory_entry_t));
|
||||
void * buffer = malloc(sizeof(btstack_link_key_db_memory_entry_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(btstack_link_key_db_memory_entry_t));
|
||||
}
|
||||
return (btstack_link_key_db_memory_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_memory_entry_t *btstack_link_key_db_memory_entry){
|
||||
free(btstack_link_key_db_memory_entry);
|
||||
@ -336,7 +393,11 @@ void btstack_memory_btstack_link_key_db_memory_entry_free(btstack_link_key_db_me
|
||||
static bnep_service_t bnep_service_storage[MAX_NR_BNEP_SERVICES];
|
||||
static btstack_memory_pool_t bnep_service_pool;
|
||||
bnep_service_t * btstack_memory_bnep_service_get(void){
|
||||
return (bnep_service_t *) btstack_memory_pool_get(&bnep_service_pool);
|
||||
void * buffer = btstack_memory_pool_get(&bnep_service_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(bnep_service_t));
|
||||
}
|
||||
return (bnep_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
||||
btstack_memory_pool_free(&bnep_service_pool, bnep_service);
|
||||
@ -352,7 +413,11 @@ void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
bnep_service_t * btstack_memory_bnep_service_get(void){
|
||||
return (bnep_service_t*) malloc(sizeof(bnep_service_t));
|
||||
void * buffer = malloc(sizeof(bnep_service_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(bnep_service_t));
|
||||
}
|
||||
return (bnep_service_t *) buffer;
|
||||
}
|
||||
void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
||||
free(bnep_service);
|
||||
@ -374,7 +439,11 @@ void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
||||
static bnep_channel_t bnep_channel_storage[MAX_NR_BNEP_CHANNELS];
|
||||
static btstack_memory_pool_t bnep_channel_pool;
|
||||
bnep_channel_t * btstack_memory_bnep_channel_get(void){
|
||||
return (bnep_channel_t *) btstack_memory_pool_get(&bnep_channel_pool);
|
||||
void * buffer = btstack_memory_pool_get(&bnep_channel_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(bnep_channel_t));
|
||||
}
|
||||
return (bnep_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
||||
btstack_memory_pool_free(&bnep_channel_pool, bnep_channel);
|
||||
@ -390,7 +459,11 @@ void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
bnep_channel_t * btstack_memory_bnep_channel_get(void){
|
||||
return (bnep_channel_t*) malloc(sizeof(bnep_channel_t));
|
||||
void * buffer = malloc(sizeof(bnep_channel_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(bnep_channel_t));
|
||||
}
|
||||
return (bnep_channel_t *) buffer;
|
||||
}
|
||||
void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
||||
free(bnep_channel);
|
||||
@ -413,7 +486,11 @@ void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
||||
static hfp_connection_t hfp_connection_storage[MAX_NR_HFP_CONNECTIONS];
|
||||
static btstack_memory_pool_t hfp_connection_pool;
|
||||
hfp_connection_t * btstack_memory_hfp_connection_get(void){
|
||||
return (hfp_connection_t *) btstack_memory_pool_get(&hfp_connection_pool);
|
||||
void * buffer = btstack_memory_pool_get(&hfp_connection_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(hfp_connection_t));
|
||||
}
|
||||
return (hfp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
|
||||
btstack_memory_pool_free(&hfp_connection_pool, hfp_connection);
|
||||
@ -429,7 +506,11 @@ void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
hfp_connection_t * btstack_memory_hfp_connection_get(void){
|
||||
return (hfp_connection_t*) malloc(sizeof(hfp_connection_t));
|
||||
void * buffer = malloc(sizeof(hfp_connection_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(hfp_connection_t));
|
||||
}
|
||||
return (hfp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
|
||||
free(hfp_connection);
|
||||
@ -452,7 +533,11 @@ void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection){
|
||||
static service_record_item_t service_record_item_storage[MAX_NR_SERVICE_RECORD_ITEMS];
|
||||
static btstack_memory_pool_t service_record_item_pool;
|
||||
service_record_item_t * btstack_memory_service_record_item_get(void){
|
||||
return (service_record_item_t *) btstack_memory_pool_get(&service_record_item_pool);
|
||||
void * buffer = btstack_memory_pool_get(&service_record_item_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(service_record_item_t));
|
||||
}
|
||||
return (service_record_item_t *) buffer;
|
||||
}
|
||||
void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
|
||||
btstack_memory_pool_free(&service_record_item_pool, service_record_item);
|
||||
@ -468,7 +553,11 @@ void btstack_memory_service_record_item_free(service_record_item_t *service_reco
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
service_record_item_t * btstack_memory_service_record_item_get(void){
|
||||
return (service_record_item_t*) malloc(sizeof(service_record_item_t));
|
||||
void * buffer = malloc(sizeof(service_record_item_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(service_record_item_t));
|
||||
}
|
||||
return (service_record_item_t *) buffer;
|
||||
}
|
||||
void btstack_memory_service_record_item_free(service_record_item_t *service_record_item){
|
||||
free(service_record_item);
|
||||
@ -491,7 +580,11 @@ void btstack_memory_service_record_item_free(service_record_item_t *service_reco
|
||||
static avdtp_stream_endpoint_t avdtp_stream_endpoint_storage[MAX_NR_AVDTP_STREAM_ENDPOINTS];
|
||||
static btstack_memory_pool_t avdtp_stream_endpoint_pool;
|
||||
avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
|
||||
return (avdtp_stream_endpoint_t *) btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
|
||||
void * buffer = btstack_memory_pool_get(&avdtp_stream_endpoint_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
|
||||
}
|
||||
return (avdtp_stream_endpoint_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
|
||||
btstack_memory_pool_free(&avdtp_stream_endpoint_pool, avdtp_stream_endpoint);
|
||||
@ -507,7 +600,11 @@ void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_st
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
avdtp_stream_endpoint_t * btstack_memory_avdtp_stream_endpoint_get(void){
|
||||
return (avdtp_stream_endpoint_t*) malloc(sizeof(avdtp_stream_endpoint_t));
|
||||
void * buffer = malloc(sizeof(avdtp_stream_endpoint_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avdtp_stream_endpoint_t));
|
||||
}
|
||||
return (avdtp_stream_endpoint_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_stream_endpoint){
|
||||
free(avdtp_stream_endpoint);
|
||||
@ -530,7 +627,11 @@ void btstack_memory_avdtp_stream_endpoint_free(avdtp_stream_endpoint_t *avdtp_st
|
||||
static avdtp_connection_t avdtp_connection_storage[MAX_NR_AVDTP_CONNECTIONS];
|
||||
static btstack_memory_pool_t avdtp_connection_pool;
|
||||
avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
|
||||
return (avdtp_connection_t *) btstack_memory_pool_get(&avdtp_connection_pool);
|
||||
void * buffer = btstack_memory_pool_get(&avdtp_connection_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avdtp_connection_t));
|
||||
}
|
||||
return (avdtp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
|
||||
btstack_memory_pool_free(&avdtp_connection_pool, avdtp_connection);
|
||||
@ -546,7 +647,11 @@ void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
avdtp_connection_t * btstack_memory_avdtp_connection_get(void){
|
||||
return (avdtp_connection_t*) malloc(sizeof(avdtp_connection_t));
|
||||
void * buffer = malloc(sizeof(avdtp_connection_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avdtp_connection_t));
|
||||
}
|
||||
return (avdtp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
|
||||
free(avdtp_connection);
|
||||
@ -569,7 +674,11 @@ void btstack_memory_avdtp_connection_free(avdtp_connection_t *avdtp_connection){
|
||||
static avrcp_connection_t avrcp_connection_storage[MAX_NR_AVRCP_CONNECTIONS];
|
||||
static btstack_memory_pool_t avrcp_connection_pool;
|
||||
avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
|
||||
return (avrcp_connection_t *) btstack_memory_pool_get(&avrcp_connection_pool);
|
||||
void * buffer = btstack_memory_pool_get(&avrcp_connection_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avrcp_connection_t));
|
||||
}
|
||||
return (avrcp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
|
||||
btstack_memory_pool_free(&avrcp_connection_pool, avrcp_connection);
|
||||
@ -585,7 +694,11 @@ void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
avrcp_connection_t * btstack_memory_avrcp_connection_get(void){
|
||||
return (avrcp_connection_t*) malloc(sizeof(avrcp_connection_t));
|
||||
void * buffer = malloc(sizeof(avrcp_connection_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avrcp_connection_t));
|
||||
}
|
||||
return (avrcp_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
|
||||
free(avrcp_connection);
|
||||
@ -608,7 +721,11 @@ void btstack_memory_avrcp_connection_free(avrcp_connection_t *avrcp_connection){
|
||||
static avrcp_browsing_connection_t avrcp_browsing_connection_storage[MAX_NR_AVRCP_BROWSING_CONNECTIONS];
|
||||
static btstack_memory_pool_t avrcp_browsing_connection_pool;
|
||||
avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
|
||||
return (avrcp_browsing_connection_t *) btstack_memory_pool_get(&avrcp_browsing_connection_pool);
|
||||
void * buffer = btstack_memory_pool_get(&avrcp_browsing_connection_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
|
||||
}
|
||||
return (avrcp_browsing_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
|
||||
btstack_memory_pool_free(&avrcp_browsing_connection_pool, avrcp_browsing_connection);
|
||||
@ -624,7 +741,11 @@ void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
avrcp_browsing_connection_t * btstack_memory_avrcp_browsing_connection_get(void){
|
||||
return (avrcp_browsing_connection_t*) malloc(sizeof(avrcp_browsing_connection_t));
|
||||
void * buffer = malloc(sizeof(avrcp_browsing_connection_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(avrcp_browsing_connection_t));
|
||||
}
|
||||
return (avrcp_browsing_connection_t *) buffer;
|
||||
}
|
||||
void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *avrcp_browsing_connection){
|
||||
free(avrcp_browsing_connection);
|
||||
@ -648,7 +769,11 @@ void btstack_memory_avrcp_browsing_connection_free(avrcp_browsing_connection_t *
|
||||
static gatt_client_t gatt_client_storage[MAX_NR_GATT_CLIENTS];
|
||||
static btstack_memory_pool_t gatt_client_pool;
|
||||
gatt_client_t * btstack_memory_gatt_client_get(void){
|
||||
return (gatt_client_t *) btstack_memory_pool_get(&gatt_client_pool);
|
||||
void * buffer = btstack_memory_pool_get(&gatt_client_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(gatt_client_t));
|
||||
}
|
||||
return (gatt_client_t *) buffer;
|
||||
}
|
||||
void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
||||
btstack_memory_pool_free(&gatt_client_pool, gatt_client);
|
||||
@ -664,7 +789,11 @@ void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
gatt_client_t * btstack_memory_gatt_client_get(void){
|
||||
return (gatt_client_t*) malloc(sizeof(gatt_client_t));
|
||||
void * buffer = malloc(sizeof(gatt_client_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(gatt_client_t));
|
||||
}
|
||||
return (gatt_client_t *) buffer;
|
||||
}
|
||||
void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
||||
free(gatt_client);
|
||||
@ -686,7 +815,11 @@ void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
||||
static whitelist_entry_t whitelist_entry_storage[MAX_NR_WHITELIST_ENTRIES];
|
||||
static btstack_memory_pool_t whitelist_entry_pool;
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
|
||||
return (whitelist_entry_t *) btstack_memory_pool_get(&whitelist_entry_pool);
|
||||
void * buffer = btstack_memory_pool_get(&whitelist_entry_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(whitelist_entry_t));
|
||||
}
|
||||
return (whitelist_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
btstack_memory_pool_free(&whitelist_entry_pool, whitelist_entry);
|
||||
@ -702,7 +835,11 @@ void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
|
||||
return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t));
|
||||
void * buffer = malloc(sizeof(whitelist_entry_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(whitelist_entry_t));
|
||||
}
|
||||
return (whitelist_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
free(whitelist_entry);
|
||||
@ -724,7 +861,11 @@ void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NR_SM_LOOKUP_ENTRIES];
|
||||
static btstack_memory_pool_t sm_lookup_entry_pool;
|
||||
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
|
||||
return (sm_lookup_entry_t *) btstack_memory_pool_get(&sm_lookup_entry_pool);
|
||||
void * buffer = btstack_memory_pool_get(&sm_lookup_entry_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(sm_lookup_entry_t));
|
||||
}
|
||||
return (sm_lookup_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
|
||||
btstack_memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry);
|
||||
@ -740,7 +881,11 @@ void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){
|
||||
return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t));
|
||||
void * buffer = malloc(sizeof(sm_lookup_entry_t));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(sm_lookup_entry_t));
|
||||
}
|
||||
return (sm_lookup_entry_t *) buffer;
|
||||
}
|
||||
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
|
||||
free(sm_lookup_entry);
|
||||
|
@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
copyright = """/*
|
||||
* Copyright (C) 2014 BlueKitchen GmbH
|
||||
*
|
||||
@ -102,6 +105,7 @@ cfile_header_begin = """
|
||||
* @brief BTstack memory management via configurable memory pools
|
||||
*
|
||||
* @note code generated by tool/btstack_memory_generator.py
|
||||
* @note returnes buffers are initialized with 0
|
||||
*
|
||||
*/
|
||||
|
||||
@ -130,7 +134,11 @@ code_template = """
|
||||
static STRUCT_TYPE STRUCT_NAME_storage[POOL_COUNT];
|
||||
static btstack_memory_pool_t STRUCT_NAME_pool;
|
||||
STRUCT_NAME_t * btstack_memory_STRUCT_NAME_get(void){
|
||||
return (STRUCT_NAME_t *) btstack_memory_pool_get(&STRUCT_NAME_pool);
|
||||
void * buffer = btstack_memory_pool_get(&STRUCT_NAME_pool);
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(STRUCT_TYPE));
|
||||
}
|
||||
return (STRUCT_NAME_t *) buffer;
|
||||
}
|
||||
void btstack_memory_STRUCT_NAME_free(STRUCT_NAME_t *STRUCT_NAME){
|
||||
btstack_memory_pool_free(&STRUCT_NAME_pool, STRUCT_NAME);
|
||||
@ -146,7 +154,11 @@ void btstack_memory_STRUCT_NAME_free(STRUCT_NAME_t *STRUCT_NAME){
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
STRUCT_NAME_t * btstack_memory_STRUCT_NAME_get(void){
|
||||
return (STRUCT_NAME_t*) malloc(sizeof(STRUCT_TYPE));
|
||||
void * buffer = malloc(sizeof(STRUCT_TYPE));
|
||||
if (buffer){
|
||||
memset(buffer, 0, sizeof(STRUCT_TYPE));
|
||||
}
|
||||
return (STRUCT_NAME_t *) buffer;
|
||||
}
|
||||
void btstack_memory_STRUCT_NAME_free(STRUCT_NAME_t *STRUCT_NAME){
|
||||
free(STRUCT_NAME);
|
||||
@ -184,10 +196,15 @@ list_of_structs = [
|
||||
["avrcp_connection"],
|
||||
["avrcp_browsing_connection"]
|
||||
]
|
||||
|
||||
list_of_le_structs = [["gatt_client", "whitelist_entry", "sm_lookup_entry"]]
|
||||
|
||||
file_name = "../src/btstack_memory"
|
||||
"""
|
||||
"""
|
||||
|
||||
btstack_root = os.path.abspath(os.path.dirname(sys.argv[0]) + '/..')
|
||||
file_name = btstack_root + "/src/btstack_memory"
|
||||
print ('Generating %s.[h|c]' % file_name)
|
||||
|
||||
f = open(file_name+".h", "w")
|
||||
writeln(f, copyright)
|
||||
|
Loading…
Reference in New Issue
Block a user