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;
}
#endif
// My code ends here.
.
.
.
The bug was observed after making FreeRTOS uses dynamic allocation in the heap.
