# Task crashes after X hours

**URL:** <https://forums.freertos.org/t/task-crashes-after-x-hours/23401>\
**Category:** Kernel\
**Created:** [July 18, 2025, 4:26pm UTC](https://forums.freertos.org/t/task-crashes-after-x-hours/23401 "2025-07-18T16:26:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dumpie124](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@Dumpie124](https://forums.freertos.org/u/Dumpie124)\
**Post date:** [July 18, 2025, 4:26pm UTC](https://forums.freertos.org/t/task-crashes-after-x-hours/23401/1 "2025-07-18T16:26:05Z")

</div>

I am working on a Freertos non arm based project. And running in to an issue that my task crashes this could be because the task overflows however this only happens after X hours I used the watermark feature to check how much my task has left this seems to be in a valid range.

I also used memory leak tools to detect memory leaks in the implementation no issues found.

During debugging when you stepback at the crash I can see that my tasks stack is inside a different task.

How can I find the reason why this is happening i tried to use hardware breackpoints on the end of the task but no luck.

---

<div class="post-metadata">

**Author:** ![jasonpcarroll](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@jasonpcarroll](https://forums.freertos.org/u/jasonpcarroll)\
**Post date:** [July 18, 2025, 8:37pm UTC](https://forums.freertos.org/t/task-crashes-after-x-hours/23401/2 "2025-07-18T20:37:03Z")

</div>

Hi @Dumpie124,  
This page gives some options for detecting stack overflows [FreeRTOS stack usage and stack overflow checking - FreeRTOS™](https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/09-Memory-management/02-Stack-usage-and-stack-overflow-checking).

Could you supply any example code, version of FreeRTOS-Kernel, and architecture you are using FreeRTOS on?

Have you tried simply increasing the stack size of the task that is overflowing?

---

<div class="post-metadata">

**Author:** ![Dumpie124](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@Dumpie124](https://forums.freertos.org/u/Dumpie124)\
**Post date:** [July 19, 2025, 11:35am UTC](https://forums.freertos.org/t/task-crashes-after-x-hours/23401/3 "2025-07-19T11:35:55Z")

</div>

Hi @jasonpcarroll,

I am using a PowerPC architecture, milticore architecture, the free rtot version is 10.4.6 version 4.0.

To answer your question I am indeed using stackoverflow detection however I am using option 2. Did not try option 1yet. Increasing the stack will only help a slight bit, i have the feeling I am heaving a fragmentation issue.

Tried to rule out some things with advanced linters but i would love to see the stack pointer just 1 step before the crash.

---

<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 21, 2025, 5:31am UTC](https://forums.freertos.org/t/task-crashes-after-x-hours/23401/4 "2025-07-21T05:31:41Z")

</div>

> [@Dumpie124](#):
>
> Tried to rule out some things with advanced linters but i would love to see the stack pointer just 1 step before the crash.

What would you do with that information? I would examine the SP at the time of crash and see if it is out of bounds. Another way is to create the task using `xTaskCreateStatic` and reserve some memory before and after the stack space used for the task. You can then put data breakpoints at the reserved memory locations to catch stack overflows.

```c
#define STACK_SIZE 512

StaticTask_t xTaskBuffer;
StackType_t xStack[STACK_SIZE + 2]; /* Reserve 2 extra slots - xStack[0]
                                       * and xStack[STACK_SIZE]. */

xHandle = xTaskCreateStatic( TaskFunction,
                             "Task_Name",
                             STACK_SIZE, /* The 2 extra slots are not used for
                                          * stack and therefore, should not
                                          * change unless there is an overflow.
                                          * */
                             NULL,
                             tskIDLE_PRIORITY,
                             &( xStack[1] ), /* xStack[0] is reserved. */
                             &( xTaskBuffer ) );

/* Now put data breakpoints on &( xStack[0] ) and &( xStack[STACK_SIZE] ).
 */

```
