# Bug in FreeRTOS??

**URL:** <https://forums.freertos.org/t/bug-in-freertos/1137>\
**Category:** Kernel\
**Created:** [March 23, 2009, 11:56am UTC](https://forums.freertos.org/t/bug-in-freertos/1137 "2009-03-23T11:56:37Z")\
**Posts on this page:** 9\
**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:** [March 23, 2009, 11:56am UTC](https://forums.freertos.org/t/bug-in-freertos/1137/1 "2009-03-23T11:56:37Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1):

Hi!!

&nbsp;&nbsp; I noticed a strange thing! When 3 tasks have been started without enough free stack system crashed! I didn’t return from last xTaskCreate! System crashed in prvAllocateTCBAndStack function - it didn’t come out from:  
&nbsp;&nbsp;&nbsp; memset( pxNewTCB-\>pxStack, tskSTACK\_FILL\_BYTE, usStackDepth \* sizeof( portSTACK\_TYPE ) );

When I simply comment this line (it is useful only when debuging) system start working correctly! It means it returned an error code from xTaskCreate function insted of hang up in this function!!

Is it a kind of bug?? Or maybe I made something wrong??

I use FreeRTOS on LPC2364 ARM7 microcontroller.

Regards  
Konoppo

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 11:59am UTC](https://forums.freertos.org/t/bug-in-freertos/1137/2 "2009-03-23T11:59:07Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/bd3d):

Most likely your linker script is wrong, or the startup code is not correctly initializing variables.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 12:14pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/3 "2009-03-23T12:14:55Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/bd3d/e4d5):

For what should I pay attention in linker script or in startup code?? In my opinion both are correct but maybe I missed something ;)…

---

<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:** [March 23, 2009, 12:21pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/4 "2009-03-23T12:21:17Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/4dc7):

If there is not enough heap space to create a task then pvPortMalloc() will return NULL and xTaskCreate() will never call memset().&nbsp; Do you mean without enough stack, or do you mean without enough heap?&nbsp; (you say stack).

Which heap implementation are you using, heap\_1, heap\_2 or heap\_3?

Which compiler are you using?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 12:21pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/5 "2009-03-23T12:21:48Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/1ef5):

OK, thanks for suggestion!! The USER\_MODE stack size was only 2kB, when the total cheap size for freeRTOS was 4kB ;)… When I changed it everything is OK now :)…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 12:25pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/6 "2009-03-23T12:25:54Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/4dc7/f95e):

I use heap\_2, and I should say “heap” instead of stack ;)… But problem Was in stack size, I think… When I increased it - everything is OK now. But I think it’s not good idea, that xTaskCreate() call memset in this situation and crash system (my uC went to address like 0xa5000000 and NOPs instruction)…

Regards  
Konoppo

---

<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:** [March 23, 2009, 12:30pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/7 "2009-03-23T12:30:22Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/4dc7/f95e/6ce1):

Are you suggesting each line if FreeRTOS should check the user has not overflowed the stack before executing - even before the scheduler has been started?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 12:37pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/8 "2009-03-23T12:37:52Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/4dc7/f95e/6ce1/a7e2):

OK, you are right, my suggestion was a bit stupid ;)… For me it wasn’t obvious that freeRTOS uses a Supervisor Stack Size…

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 23, 2009, 1:00pm UTC](https://forums.freertos.org/t/bug-in-freertos/1137/9 "2009-03-23T13:00:31Z")

</div>

**[konoppo](https://sourceforge.net/u/konoppo/)** wrote on [Monday, March 23, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/3299bb8c/#81f1/4dc7/ab54):

OK, please, tell me - which memory is used by freeRTOS for “heap”?? It’s a free RAM (bss\_section) or it’s stored in the stac region?? I thought that heap uses the stack region but now I think that it’s stored in BSS section (like any other variable)… I use GCC…
