heap: Fix heap_freemem() when all the heap is full.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 19 Apr 2010 22:41:40 +0000 (22:41 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 19 Apr 2010 22:41:40 +0000 (22:41 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3469 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/struct/heap.c

index 33c6de2acadca599ee7057a4dc6710df16a4fba8..b8d06701cbc04c9dd8766cf71743d1d3ae019f49 100644 (file)
@@ -127,9 +127,9 @@ void heap_freemem(struct Heap* h, void *mem, size_t size)
        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);
-       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;