# Compile error on Arduino with configUSE\_MALLOC\_FAILED\_HOOK=0

**URL:** <https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165>\
**Category:** Kernel\
**Created:** [April 26, 2018, 11:22pm UTC](https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165 "2018-04-26T23:22:39Z")\
**Posts on this page:** 4\
**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:** [April 26, 2018, 11:22pm UTC](https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165/1 "2018-04-26T23:22:39Z")

</div>

**[roxy3d](https://sourceforge.net/u/roxy3d/)** wrote on [Thursday, April 26, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/3d6c0636/#2776):

Hello! I’m trying to slip FreeRTOS under Marlin (the 3D Printing firmware) and have run into a problem. I want to keep trying to xCreateTask() with decreasing amounts of stack memory until the task starts successfully. In order to do that, I need configUSE\_MALLOC\_FAILED\_HOOK=0 (or else the malloc() routines will lock up with the board’s LED blinking).

I can’t do that because vTaskStartScheduler() makes a call to vApplicationMallocFailedHook();

Can we make a small change in the release version of FreeRTOS as described below? It is easy enough to make the change, but the distribution of the needed change is difficult. Marlin uses the GNU license and it would be messy for use to distribute a modified version of FreeRTOS.

```auto
void initVariant(void)
{
#if defined(USBCON)
	USBDevice.attach();
#endif

	setup(); // the normal Arduino setup() function is run here.

	vTaskStartScheduler(); // initialise and run the freeRTOS scheduler. Execution should never return here.

#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
	vApplicationMallocFailedHook(); // Probably we've failed trying to initialise heap for the scheduler. Let someone know.
#endif
HANG: goto HANG;
      return;
}

```

---

<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:** [April 27, 2018, 3:43am UTC](https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165/2 "2018-04-27T03:43:53Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, April 27, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/3d6c0636/#2776/7825):

You can implement vApplicationMallocFailedHook() to do whatever you  
want. It sounds like you have default debug configuration that is just  
halting execution if it is called, but normally in production code an  
allocation failure would be handled gracefully (as you are trying to do)  
rather than be considered a fatal error.

The call to vApplicationMallocFailedHook() after vTaskStartScheduler()  
appears to be obsolete as if the scheduler can’t start, then it failed  
to create the stack for either the idle or timer task, in which case  
vApplicationMallocFailedHook() will already have been called.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 27, 2018, 8:39pm UTC](https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165/3 "2018-04-27T20:39:12Z")

</div>

**[roxy3d](https://sourceforge.net/u/roxy3d/)** wrote on [Friday, April 27, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/3d6c0636/#8f01):

May I request we delete the obsolete call to vApplicationMallocFailedHook() after vTaskStartScheduler() for the next release? I’m hoping I can get everything working with no code changes to the FreeRTOS library for Arduino! 🙂

---

<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:** [April 27, 2018, 8:42pm UTC](https://forums.freertos.org/t/compile-error-on-arduino-with-configuse-malloc-failed-hook-0/7165/4 "2018-04-27T20:42:08Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, April 27, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/3d6c0636/#8f01/4a8a):

That main file is not something we provided :o) Please submit this  
request to whomever supplied it.
