pvPortMalloc fails and faults

A call to pvPortMalloc in a specific task causes a fault. Processor is MC/Atmel SAM D51. pvPortMalloc() never returns. The FreeRTOS was set up by the Harmony system that Microchip created.

I’ve never had this particular issue with other processors. Does anyone have an idea what might be causing the issue. Snippet of code below:

// allocate decode argument
   while (pHandle == NULL) {
      vTaskDelay (pdMS_TO_TICKS(10000));
      pHandle = (void *)pvPortMalloc(sizeof(DECODE_Handle_t));
      //if (pHandle == NULL) { continue; }
      log_info ("%s: heap size %d", __func__, xPortGetFreeHeapSize());
      // initialize handle members
      //memset (pHandle, 0, sizeof (DECODE_Handle_t));
      //pHandle->pCfg = pCfg;
   }

Any ideas would be appreciated. Thanks.

Your description is a little bit confusing.

if pvPortMalloc actually “faults”, the problem is almost certainly that your program has done something to corrupt the heap. Either by writting outside of the bounds of allocated memory, using memory after a pvPortFree of the memory, calling pvPortFree a second time on a given pointer, or on a pointer that didn’t come from pvPortMalloc.

if pvPortMalloc just doesn’t return, it might be that you have enable the Malloc Fail Hook, and you ran out of memory.

Found my issue. I was exiting the task without deleting the task from the scheduler. Went to prvTaskExitError() and never returned. Thanks.

1 Like