# Infinite loop

**URL:** <https://forums.freertos.org/t/infinite-loop/1215>\
**Category:** Kernel\
**Created:** [September 14, 2005, 7:27pm UTC](https://forums.freertos.org/t/infinite-loop/1215 "2005-09-14T19:27:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 14, 2005, 7:27pm UTC](https://forums.freertos.org/t/infinite-loop/1215/1 "2005-09-14T19:27:35Z")

</div>

**nobody** wrote on [Wednesday, September 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/3492cae7/#b333):

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxPreviousBlock = &xStart;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxBlock = xStart.pxNextFreeBlock;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while( ( pxBlock-\>xBlockSize \< xWantedSize ) && ( pxBlock-\>pxNextFreeBlock ) )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxPreviousBlock = pxBlock;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pxBlock = pxBlock-\>pxNextFreeBlock;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

Richard,

I’m still having this looping problem within heap2 in the above code.&nbsp; It does appear to occur randomly.&nbsp;&nbsp; I’ve tried everything to understand this, except for beating my head against a wall 🙂

If I step through the above code, the value of pxBlock is always the same.&nbsp; IE the linked list seems to be linked to the same cell.

My guess is that there is a critical area somewhere which is not protected and an interrupt has sneaked it…&nbsp; Any ideas.

Thanks  
Phil

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [September 14, 2005, 7:50pm UTC](https://forums.freertos.org/t/infinite-loop/1215/2 "2005-09-14T19:50:03Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, September 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/3492cae7/#b333/bbd3):

Thats interesting.&nbsp; I will have to run through the test code to re-familiarise myself with this function to see if I can work out how this could happen.

Before you enter the loop pxBlock is set to the address of xStart.&nbsp; Is this still the case when you start looping forever, or does the loop execute correctly for a bit before getting stuck.&nbsp; Alternatively, If you are able to inspect xStart from within your debugger, then does xStart.pxNextFreeBlock point back to xStart?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 14, 2005, 7:54pm UTC](https://forums.freertos.org/t/infinite-loop/1215/3 "2005-09-14T19:54:11Z")

</div>

**nobody** wrote on [Wednesday, September 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/3492cae7/#b333/a07f):

Will check and see.

Phil
