diff --git a/hal/common/mbed_alloc_wrappers.cpp b/hal/common/mbed_alloc_wrappers.cpp index acd6b620af2..1db3985cb02 100644 --- a/hal/common/mbed_alloc_wrappers.cpp +++ b/hal/common/mbed_alloc_wrappers.cpp @@ -46,15 +46,23 @@ typedef struct { uint32_t pad; } alloc_info_t; -static SingletonPtr malloc_stats_mutex; +#ifdef MBED_MEM_TRACING_ENABLED static SingletonPtr mem_trace_mutex; +#endif +#ifdef MBED_HEAP_STATS_ENABLED +static SingletonPtr malloc_stats_mutex; static mbed_stats_heap_t heap_stats = {0, 0, 0, 0, 0}; +#endif void mbed_stats_heap_get(mbed_stats_heap_t *stats) { +#ifdef MBED_HEAP_STATS_ENABLED malloc_stats_mutex->lock(); memcpy(stats, &heap_stats, sizeof(mbed_stats_heap_t)); malloc_stats_mutex->unlock(); +#else + memset(stats, 0, sizeof(mbed_stats_heap_t)); +#endif } /******************************************************************************/ @@ -259,12 +267,12 @@ extern "C" void* $Sub$$realloc(void *ptr, size_t size) { free(ptr); } #else // #ifdef MBED_HEAP_STATS_ENABLED - mem_trace_mutex->lock(); new_ptr = $Super$$realloc(ptr, size); - mem_trace_mutex->unlock(); #endif // #ifdef MBED_HEAP_STATS_ENABLED #ifdef MBED_MEM_TRACING_ENABLED + mem_trace_mutex->lock(); mbed_mem_trace_realloc(new_ptr, ptr, size, MBED_CALLER_ADDR()); + mem_trace_mutex->unlock(); #endif // #ifdef MBED_MEM_TRACING_ENABLED return new_ptr; }