Declare vApplicationMallocFailedHook function in task.h instead in each C heap file (#483)

vApplicationMallocFailedHook was declared in each Heap file. which forces users to declare it and can cause problems if the prototype of the function changes.

Co-authored-by: Pierre-Noel Bouteville <pnb990@gmail.com>
diff --git a/.github/lexicon.txt b/.github/lexicon.txt
index 3263b08..718b0b3 100644
--- a/.github/lexicon.txt
+++ b/.github/lexicon.txt
@@ -2476,6 +2476,7 @@
 vapplicationgettimertaskmemory
 vapplicationidlehook
 vapplicationirqhandler
+vapplicationmallocfailedhook
 vapplicationsetuptickinterrupt
 vapplicationsetupticktimerinterrupt
 vapplicationsetuptimerinterrupt
diff --git a/include/portable.h b/include/portable.h
index 0feedad..d0c3b90 100644
--- a/include/portable.h
+++ b/include/portable.h
@@ -188,6 +188,19 @@
     #define vPortFreeStack       vPortFree

 #endif

 

+#if ( configUSE_MALLOC_FAILED_HOOK == 1 )

+

+/**

+ * task.h

+ * @code{c}

+ * void vApplicationMallocFailedHook( void )

+ * @endcode

+ *

+ * This hook function is called when allocation failed.

+ */

+    void vApplicationMallocFailedHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */

+#endif

+

 /*

  * Setup the hardware ready for the scheduler to take control.  This generally

  * sets up a tick interrupt and sets timers for the correct tick frequency.

diff --git a/portable/MemMang/heap_1.c b/portable/MemMang/heap_1.c
index 67825f5..9c7c523 100644
--- a/portable/MemMang/heap_1.c
+++ b/portable/MemMang/heap_1.c
@@ -118,7 +118,6 @@
     {

         if( pvReturn == NULL )

         {

-            extern void vApplicationMallocFailedHook( void );

             vApplicationMallocFailedHook();

         }

     }

diff --git a/portable/MemMang/heap_2.c b/portable/MemMang/heap_2.c
index 163a12e..0700a0d 100644
--- a/portable/MemMang/heap_2.c
+++ b/portable/MemMang/heap_2.c
@@ -249,7 +249,6 @@
     {

         if( pvReturn == NULL )

         {

-            extern void vApplicationMallocFailedHook( void );

             vApplicationMallocFailedHook();

         }

     }

diff --git a/portable/MemMang/heap_3.c b/portable/MemMang/heap_3.c
index 6accd48..8ed3d1b 100644
--- a/portable/MemMang/heap_3.c
+++ b/portable/MemMang/heap_3.c
@@ -71,7 +71,6 @@
     {

         if( pvReturn == NULL )

         {

-            extern void vApplicationMallocFailedHook( void );

             vApplicationMallocFailedHook();

         }

     }

diff --git a/portable/MemMang/heap_4.c b/portable/MemMang/heap_4.c
index 33bb818..90a20c5 100644
--- a/portable/MemMang/heap_4.c
+++ b/portable/MemMang/heap_4.c
@@ -269,7 +269,6 @@
     {

         if( pvReturn == NULL )

         {

-            extern void vApplicationMallocFailedHook( void );

             vApplicationMallocFailedHook();

         }

         else

diff --git a/portable/MemMang/heap_5.c b/portable/MemMang/heap_5.c
index b330439..4fea255 100644
--- a/portable/MemMang/heap_5.c
+++ b/portable/MemMang/heap_5.c
@@ -279,7 +279,6 @@
     {

         if( pvReturn == NULL )

         {

-            extern void vApplicationMallocFailedHook( void );

             vApplicationMallocFailedHook();

         }

         else