Complete the code to allocate memory safely in FreeRTOS.
void *ptr = pvPortMalloc([1]);Using size tells FreeRTOS how much memory to allocate, preventing errors.
Complete the code to check if memory allocation was successful.
if (ptr == [1]) { // handle error }
FreeRTOS returns NULL if memory allocation fails, so checking for NULL prevents crashes.
Fix the error in the code to free allocated memory correctly.
vPortFree([1]);You must pass the pointer returned by pvPortMalloc to vPortFree to release memory properly.
Fill both blanks to create a safe memory allocation and check.
void *ptr = pvPortMalloc([1]); if (ptr == [2]) { // handle error }
First, allocate memory with size. Then check if ptr is NULL to avoid crashes.
Fill all three blanks to allocate, check, and free memory safely.
void *ptr = pvPortMalloc([1]); if (ptr == [2]) { // handle error } else { vPortFree([3]); }
Allocate memory with size, check if ptr is NULL, then free the allocated ptr to prevent leaks and crashes.
