From 727baa0027009f19a5fffb2688d9312531d57548 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Mon, 16 Sep 2024 08:05:09 +0100 Subject: [PATCH] Fix MallocCount for MinGW MinGW defines aliases in stdlib.h for `realloc` and `free` which require wrapping. --- Sming/Components/malloc_count/component.mk | 5 +++++ Sming/Components/malloc_count/malloc_count.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Sming/Components/malloc_count/component.mk b/Sming/Components/malloc_count/component.mk index 7089c0962f..5579848cd1 100644 --- a/Sming/Components/malloc_count/component.mk +++ b/Sming/Components/malloc_count/component.mk @@ -29,6 +29,11 @@ MC_WRAP_FUNCS += \ pvPortZallocIram \ vPortFree endif +ifeq ($(SMING_ARCH)$(UNAME),HostWindows) +MC_WRAP_FUNCS += \ + __mingw_realloc \ + __mingw_free +endif EXTRA_LDFLAGS := $(call UndefWrap,$(MC_WRAP_FUNCS)) diff --git a/Sming/Components/malloc_count/malloc_count.cpp b/Sming/Components/malloc_count/malloc_count.cpp index 6766a8e46b..d886933dee 100644 --- a/Sming/Components/malloc_count/malloc_count.cpp +++ b/Sming/Components/malloc_count/malloc_count.cpp @@ -364,6 +364,11 @@ extern "C" void WRAP(free)(void*) __attribute__((alias("mc_free"))); using namespace MallocCount; +#ifdef __WIN32 +extern "C" void* WRAP(__mingw_realloc)(void*, size_t) __attribute__((alias("mc_realloc"))); +extern "C" void WRAP(__mingw_free)(void*) __attribute__((alias("mc_free"))); +#endif + #ifdef ARCH_ESP8266 extern "C" void* WRAP(pvPortMalloc)(size_t) __attribute__((alias("mc_malloc")));