Module: xenomai-jki
Branch: for-forge
Commit: 32ef08b18597c74ec873100c9e1c343565f6956e
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=32ef08b18597c74ec873100c9e1c343565f6956e

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Thu Sep 15 18:08:41 2016 +0200

copperplate: Fix bucket freelist initialization when using new blocks

When we pull a block from the free range, it does not contain a
freelist in its head.

This fixes a crash on such an allocation/release pattern:

    p = xnmalloc(1400);
    p[0] = -1;
    xnfree(p);
    xnmalloc(512);
    xnmalloc(512);

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 lib/copperplate/heapobj-pshared.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index f4c6f37..7de4690 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -439,6 +439,7 @@ static void *alloc_block(struct shared_heap *heap, size_t 
size)
                                goto done;
                        if (bsize <= HOBJ_PAGE_SIZE)
                                heap->buckets[ilog].fcount += (HOBJ_PAGE_SIZE 
>> log2size) - 1;
+                       heap->buckets[ilog].freelist = 0;
                } else {
                        if (bsize <= HOBJ_PAGE_SIZE)
                                --heap->buckets[ilog].fcount;
@@ -453,9 +454,9 @@ static void *alloc_block(struct shared_heap *heap, size_t 
size)
                found:
                        pgnum = (__shoff(base, block) - extent->membase) >> 
HOBJ_PAGE_SHIFT;
                        ++extent->pagemap[pgnum].bcount;
+                       heap->buckets[ilog].freelist = *((memoff_t *)block);
                }
 
-               heap->buckets[ilog].freelist = *((memoff_t *)block);
                heap->ubytes += bsize;
        } else {
                if (size > heap->maxcont)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to