mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-09-13 13:49:58 +00:00
Fix MallocThenReallocGrowsMemoryInPlace
The realloc was not taking in account extra bytes needed for the the pointer proper alignment
This commit is contained in:
@@ -317,12 +317,16 @@ void* unity_realloc(void* oldMem, size_t size)
|
|||||||
if (guard->size >= size) return oldMem;
|
if (guard->size >= size) return oldMem;
|
||||||
|
|
||||||
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */
|
#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */
|
||||||
if (oldMem == unity_heap + heap_index - guard->size - sizeof(end) &&
|
{
|
||||||
heap_index + size - guard->size <= UNITY_INTERNAL_HEAP_SIZE_BYTES)
|
size_t old_total_size = unity_size_round_up(guard->size + sizeof(end));
|
||||||
|
|
||||||
|
if ((oldMem == unity_heap + heap_index - old_total_size) &&
|
||||||
|
((heap_index - old_total_size + unity_size_round_up(size + sizeof(end))) <= UNITY_INTERNAL_HEAP_SIZE_BYTES))
|
||||||
{
|
{
|
||||||
release_memory(oldMem); /* Not thread-safe, like unity_heap generally */
|
release_memory(oldMem); /* Not thread-safe, like unity_heap generally */
|
||||||
return unity_malloc(size); /* No memcpy since data is in place */
|
return unity_malloc(size); /* No memcpy since data is in place */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
newMem = unity_malloc(size);
|
newMem = unity_malloc(size);
|
||||||
if (newMem == NULL) return NULL; /* Do not release old memory */
|
if (newMem == NULL) return NULL; /* Do not release old memory */
|
||||||
|
|||||||
Reference in New Issue
Block a user