Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to allocate memory safely in FreeRTOS.
FreeRTOS
void *ptr = pvPortMalloc([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL or zero causes no memory to be allocated.
✗ Incorrect
Using size tells FreeRTOS how much memory to allocate, preventing errors.
2fill in blank
mediumComplete the code to check if memory allocation was successful.
FreeRTOS
if (ptr == [1]) { // handle error }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking against zero or the pointer itself instead of NULL.
✗ Incorrect
FreeRTOS returns NULL if memory allocation fails, so checking for NULL prevents crashes.
3fill in blank
hardFix the error in the code to free allocated memory correctly.
FreeRTOS
vPortFree([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL or size instead of the pointer.
✗ Incorrect
You must pass the pointer returned by pvPortMalloc to vPortFree to release memory properly.
4fill in blank
hardFill both blanks to create a safe memory allocation and check.
FreeRTOS
void *ptr = pvPortMalloc([1]); if (ptr == [2]) { // handle error }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or ptr instead of size and NULL.
✗ Incorrect
First, allocate memory with size. Then check if ptr is NULL to avoid crashes.
5fill in blank
hardFill all three blanks to allocate, check, and free memory safely.
FreeRTOS
void *ptr = pvPortMalloc([1]); if (ptr == [2]) { // handle error } else { vPortFree([3]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variables or forgetting to check for NULL.
✗ Incorrect
Allocate memory with size, check if ptr is NULL, then free the allocated ptr to prevent leaks and crashes.