Invalid task error value during initialization

When creating a new task, the task error value is not initialized to zero. The variable pxNewTCB->iTaskErrno will end up taking what was in the memory address where it is located.

The fix is to initialize the TCB error value during initialization. Here is a suggested fix to the bug:
the following function is located in tasks.c file:

static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
                                  const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
                                  const uint32_t ulStackDepth,
                                  void * const pvParameters,
                                  UBaseType_t uxPriority,
                                  TaskHandle_t * const pxCreatedTask,
                                  TCB_t * pxNewTCB,
                                  const MemoryRegion_t * const xRegions )
    StackType_t * pxTopOfStack;
    UBaseType_t x;

    // My code starts here.
    #if ( configUSE_POSIX_ERRNO == 1 )
            /* Initialize task error value to zero. */
            pxNewTCB->iTaskErrno = 0;
    // My code ends here.

The bug was observed after making FreeRTOS uses dynamic allocation in the heap.

For reference, also was posted to GitHub here: Initialize task error value to zero when creating the TCB of a new task · Issue #1188 · FreeRTOS/FreeRTOS · GitHub

We’d welcome a PR if you’d prefer to do so, else I can open the PR.

The complete TCB is zeroed out here using memset - FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub. Which FreeRTOS version are you using? Can you share your task creation code?

I verified it on a Cortex-M7 platform and iTaskErrorno is initizlied to zero: