diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 575f9e9..01d3ae6 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -196,7 +196,7 @@ void * unity_malloc(size_t size) malloc_count++; - guard = (Guard*)malloc(size + sizeof(Guard) + 4); + guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4); guard->size = size; mem = (char*)&(guard[1]); memcpy(&mem[size], end, strlen(end) + 1); @@ -219,7 +219,7 @@ static void release_memory(void * mem) guard--; malloc_count--; - free(guard); + UNITY_FIXTURE_FREE(guard); } void unity_free(void * mem) diff --git a/extras/fixture/src/unity_fixture_malloc_overrides.h b/extras/fixture/src/unity_fixture_malloc_overrides.h index a19c1ea..27b9884 100644 --- a/extras/fixture/src/unity_fixture_malloc_overrides.h +++ b/extras/fixture/src/unity_fixture_malloc_overrides.h @@ -10,6 +10,28 @@ #include +// This function is used by the Unity Fixture to allocate memory on +// the heap and can be overridden with platform-specific heap +// implementations. For example, when using FreeRTOS +// UNITY_FIXTURE_MALLOC becomes pvPortMalloc(). + +#ifndef UNITY_FIXTURE_MALLOC + #define UNITY_FIXTURE_MALLOC( SIZE ) malloc( ( SIZE ) ) +#else + extern void * UNITY_FIXTURE_MALLOC(size_t size); +#endif + +// This function is used by the Unity Fixture to release memory in the +// heap and can be overridden with platform-specific heap +// implementations. For example, when using FreeRTOS +// UNITY_FIXTURE_FREE becomes vPortFree(). + +#ifndef UNITY_FIXTURE_FREE + #define UNITY_FIXTURE_FREE( PTR ) free( ( PTR ) ) +#else + extern void UNITY_FIXTURE_FREE(void *ptr); +#endif + #define malloc unity_malloc #define calloc unity_calloc #define realloc unity_realloc