# pvPortMalloc blocking at configassert of splitting the block into two blocks

**URL:** <https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269>\
**Category:** Libraries\
**Created:** [July 16, 2020, 9:47am UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269 "2020-07-16T09:47:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![saiteja](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@saiteja](https://forums.freertos.org/u/saiteja)\
**Post date:** [July 16, 2020, 9:47am UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/1 "2020-07-16T09:47:29Z")

</div>

I am facing a strange issue where the malloc search for a block that is having free space than the wanted size but after 4 successful malloc allocations the the xstart.pxnextfreeblock is pointing to 0xffffffff(pxBlock = xStart.pxNextFreeBlock;) and it is having size of some junk value and is trying to get allocated and after that it is going to config assert check where the block is not aligned as per requirements  
configASSERT( ( ( ( size\_t ) pxNewBlockLink ) & portBYTE\_ALIGNMENT\_MASK ) == 0 );  
Thanks for your time.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [July 16, 2020, 10:24am UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/2 "2020-07-16T10:24:11Z")

</div>

It would help a lot, if you add the required information at the 1st place.:  
Which FreeRTOS version, the selected heap variant, corresponding FreeRTOSConfig.h items, etc.

---

<div class="post-metadata">

**Author:** ![saiteja](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@saiteja](https://forums.freertos.org/u/saiteja)\
**Post date:** [July 16, 2020, 10:55am UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/3 "2020-07-16T10:55:57Z")

</div>

Sorry I forgot to add it. I am using heap4.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [July 16, 2020, 11:08am UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/4 "2020-07-16T11:08:00Z")

</div>

My first guess would be something that is using an allocated block is writing outside the block it has gotten, and corrupting the structure of the heap.

---

<div class="post-metadata">

**Author:** ![saiteja](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@saiteja](https://forums.freertos.org/u/saiteja)\
**Post date:** [July 16, 2020, 12:02pm UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/5 "2020-07-16T12:02:50Z")

</div>

no, by the time I am getting this error it is still allocating and nothing is being performed on any allocated block.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 16, 2020, 3:32pm UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/6 "2020-07-16T15:32:14Z")

</div>

That seems like a memory corruption - would you please try to find when `xStart.pxNextFreeBlock` gets set to `0xffffffff`. You can try to put a data breakpoint on `xStart.pxNextFreeBlock` to catch when it gets updated unexpectedly.

Thanks.

---

<div class="post-metadata">

**Author:** ![saiteja](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@saiteja](https://forums.freertos.org/u/saiteja)\
**Post date:** [July 20, 2020, 12:33pm UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/7 "2020-07-20T12:33:47Z")

</div>

what I have observed is after 4 or 5 allocations the next block of xStart is 0x00. And next time it is pointing to memfaulthandler address of nvic and freebytesize of almost 4 lakh

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [July 20, 2020, 3:16pm UTC](https://forums.freertos.org/t/pvportmalloc-blocking-at-configassert-of-splitting-the-block-into-two-blocks/10269/8 "2020-07-20T15:16:19Z")

</div>

Because of the “end marker”,`xStart.pxNextFreeBlock` should never be NULL: [https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/portable/MemMang/heap\_4.c#L359](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/portable/MemMang/heap_4.c#L359)

If it is after 4-5 allocations, it should be relatively easy to put a data breakpoint. Put a data breakpoint for `xStart.pxNextFreeBlock` changes. It will cause the program to break in debugger whenever `xStart.pxNextFreeBlock` changes. You can then examine the callstack to see if it is a legitimate change or a memory corruption.

Thanks.
