diff --git a/nimble/host/services/bleuart/src/bleuart.c b/nimble/host/services/bleuart/src/bleuart.c index 570322450..866595ede 100644 --- a/nimble/host/services/bleuart/src/bleuart.c +++ b/nimble/host/services/bleuart/src/bleuart.c @@ -28,6 +28,7 @@ #include "bleuart/bleuart.h" #include "os/endian.h" #include "console/console.h" +#include "esp_nimble_mem.h" /* ble uart attr read handle */ uint16_t g_bleuart_attr_read_handle; @@ -198,6 +199,6 @@ bleuart_init(void) rc = console_init(bleuart_uart_read); SYSINIT_PANIC_ASSERT(rc == 0); - console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT)); + console_buf = nimble_platform_mem_malloc(MYNEWT_VAL(BLEUART_MAX_INPUT)); SYSINIT_PANIC_ASSERT(console_buf != NULL); } diff --git a/nimble/host/src/ble_att_svr.c b/nimble/host/src/ble_att_svr.c index 0cf9b040a..f00b2cb00 100644 --- a/nimble/host/src/ble_att_svr.c +++ b/nimble/host/src/ble_att_svr.c @@ -25,6 +25,7 @@ #include "nimble/ble.h" #include "host/ble_uuid.h" #include "ble_hs_priv.h" +#include "esp_nimble_mem.h" #if NIMBLE_BLE_CONNECT /** @@ -2710,7 +2711,7 @@ ble_att_svr_reset(void) static void ble_att_svr_free_start_mem(void) { - free(ble_att_svr_entry_mem); + nimble_platform_mem_free(ble_att_svr_entry_mem); ble_att_svr_entry_mem = NULL; } @@ -2722,7 +2723,7 @@ ble_att_svr_start(void) ble_att_svr_free_start_mem(); if (ble_hs_max_attrs > 0) { - ble_att_svr_entry_mem = malloc( + ble_att_svr_entry_mem = nimble_platform_mem_malloc( OS_MEMPOOL_BYTES(ble_hs_max_attrs, sizeof (struct ble_att_svr_entry))); if (ble_att_svr_entry_mem == NULL) { diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index a465e9445..1ed45b36e 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -25,6 +25,7 @@ #include "host/ble_uuid.h" #include "host/ble_store.h" #include "ble_hs_priv.h" +#include "esp_nimble_mem.h" #define BLE_GATTS_INCLUDE_SZ 6 #define BLE_GATTS_CHR_MAX_SZ 19 @@ -1155,7 +1156,7 @@ ble_gatts_connection_broken(uint16_t conn_handle) static void ble_gatts_free_svc_defs(void) { - free(ble_gatts_svc_defs); + nimble_platform_mem_free(ble_gatts_svc_defs); ble_gatts_svc_defs = NULL; ble_gatts_num_svc_defs = 0; } @@ -1163,10 +1164,10 @@ ble_gatts_free_svc_defs(void) static void ble_gatts_free_mem(void) { - free(ble_gatts_clt_cfg_mem); + nimble_platform_mem_free(ble_gatts_clt_cfg_mem); ble_gatts_clt_cfg_mem = NULL; - free(ble_gatts_svc_entries); + nimble_platform_mem_free(ble_gatts_svc_entries); ble_gatts_svc_entries = NULL; } @@ -1210,7 +1211,7 @@ ble_gatts_start(void) } if (ble_hs_max_client_configs > 0) { - ble_gatts_clt_cfg_mem = malloc( + ble_gatts_clt_cfg_mem = nimble_platform_mem_malloc( OS_MEMPOOL_BYTES(ble_hs_max_client_configs, sizeof (struct ble_gatts_clt_cfg))); if (ble_gatts_clt_cfg_mem == NULL) { @@ -1221,7 +1222,7 @@ ble_gatts_start(void) if (ble_hs_max_services > 0) { ble_gatts_svc_entries = - malloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries); + nimble_platform_mem_malloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries); if (ble_gatts_svc_entries == NULL) { rc = BLE_HS_ENOMEM; goto done; diff --git a/porting/nimble/src/mem.c b/porting/nimble/src/mem.c index a56fa1710..738763cc3 100644 --- a/porting/nimble/src/mem.c +++ b/porting/nimble/src/mem.c @@ -20,6 +20,7 @@ #include #include "os/os.h" #include "mem/mem.h" +#include "esp_nimble_mem.h" /** * Generic mempool allocation function. Used with basic and extended mempools. @@ -31,7 +32,7 @@ mem_malloc_mempool_gen(uint16_t num_blocks, uint32_t block_size, block_size = OS_ALIGN(block_size, OS_ALIGNMENT); if (num_blocks > 0) { - *out_buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size)); + *out_buf = nimble_platform_mem_malloc(OS_MEMPOOL_BYTES(num_blocks, block_size)); if (*out_buf == NULL) { return OS_ENOMEM; } @@ -72,7 +73,7 @@ mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks, rc = os_mempool_init(mempool, num_blocks, block_size, buf, name); if (rc != 0) { - free(buf); + nimble_platform_mem_free(buf); return rc; } @@ -113,7 +114,7 @@ mem_malloc_mempool_ext(struct os_mempool_ext *mpe, uint16_t num_blocks, rc = os_mempool_ext_init(mpe, num_blocks, block_size, buf, name); if (rc != 0) { - free(buf); + nimble_platform_mem_free(buf); return rc; } @@ -160,7 +161,7 @@ mem_malloc_mbuf_pool(struct os_mempool *mempool, rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks); if (rc != 0) { - free(buf); + nimble_platform_mem_free(buf); return rc; } diff --git a/porting/nimble/src/os_msys_init.c b/porting/nimble/src/os_msys_init.c index 2b9ca029f..597d6ed5e 100644 --- a/porting/nimble/src/os_msys_init.c +++ b/porting/nimble/src/os_msys_init.c @@ -21,6 +21,7 @@ #include "os/os.h" #include "mem/mem.h" #include "sysinit/sysinit.h" +#include "esp_nimble_mem.h" static STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list = STAILQ_HEAD_INITIALIZER(g_msys_pool_list); @@ -122,14 +123,14 @@ int os_msys_buf_alloc(void) { #if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0 - os_msys_init_1_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE)); + os_msys_init_1_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE)); if (!os_msys_init_1_data) { return -1; } #endif #if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0 - os_msys_init_2_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE)); + os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE)); if (!os_msys_init_2_data) { return -1; } @@ -142,12 +143,12 @@ void os_msys_buf_free(void) { #if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0 - free(os_msys_init_1_data); + nimble_platform_mem_free(os_msys_init_1_data); os_msys_init_1_data = NULL; #endif #if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0 - free(os_msys_init_2_data); + nimble_platform_mem_free(os_msys_init_2_data); os_msys_init_2_data = NULL; #endif