if (!size)
size = sizeof(MemChunk);
if (!size)
size = sizeof(MemChunk);
- /* Special case: first chunk in the free list */
+ /* Special cases: first chunk in the free list or memory completely full */
ASSERT((uint8_t*)mem != (uint8_t*)h->FreeList);
ASSERT((uint8_t*)mem != (uint8_t*)h->FreeList);
- if (((uint8_t *)mem) < ((uint8_t *)h->FreeList))
+ if (((uint8_t *)mem) < ((uint8_t *)h->FreeList) || !h->FreeList)
{
/* Insert memory block before the current free list head */
prev = (MemChunk *)mem;
{
/* Insert memory block before the current free list head */
prev = (MemChunk *)mem;