Skip to content

Commit 7fc55e2

Browse files
committed
[crypto] Do not use otPlatCAlloc and otPlatFree directly in mbedtls
This commit changes the default configuration of heap memory in mbedtls when OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE is enabled. This is necessary to pass the unit tests which keep track of heap memory with crypto backend that allocates memory during the test. Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
1 parent 356ff34 commit 7fc55e2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/core/crypto/mbedtls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ MbedTls::MbedTls(void)
5757
// mbedTLS's debug level is almost the same as OpenThread's
5858
mbedtls_debug_set_threshold(OPENTHREAD_CONFIG_LOG_LEVEL);
5959
#endif
60-
#if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
60+
#if OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
6161
mbedtls_platform_set_calloc_free(Heap::CAlloc, Heap::Free);
62-
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
62+
#endif // OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
6363
}
6464

6565
Error MbedTls::MapError(int aMbedTlsError)

third_party/mbedtls/mbedtls-config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@
134134
#define MBEDTLS_ENTROPY_MAX_SOURCES 1 /**< Maximum number of sources supported */
135135

136136
#if OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
137-
#define MBEDTLS_PLATFORM_STD_CALLOC otPlatCAlloc /**< Default allocator to use, can be undefined */
138-
#define MBEDTLS_PLATFORM_STD_FREE otPlatFree /**< Default free to use, can be undefined */
137+
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
138+
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
139139
#else
140140
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
141141
#endif

0 commit comments

Comments
 (0)