From 3cb6f28a9ac13ff8d47adf30d68f06c6314a6a83 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 16 Sep 2024 10:37:13 +0100 Subject: [PATCH] Fix MallocCount for MinGW (#2884) 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")));