Bird
0
0

Identify the error in this FreeRTOS memory management code:

medium📝 Debug Q6 of 15
FreeRTOS - Memory Management
Identify the error in this FreeRTOS memory management code:
void *ptr = pvPortMalloc(50);
// Missing NULL check
memcpy(ptr, source, 50);
ANot checking if pvPortMalloc returned NULL before use
BUsing memcpy instead of memmove
CAllocating too much memory
DForgetting to free ptr immediately
Step-by-Step Solution
Solution:
  1. Step 1: Review memory allocation safety

    pvPortMalloc can return NULL if allocation fails; using ptr without check risks crash.
  2. Step 2: Identify missing safety check

    The code uses ptr directly without verifying it is not NULL.
  3. Final Answer:

    Not checking if pvPortMalloc returned NULL before use -> Option A
  4. Quick Check:

    Always check allocation result before use [OK]
Quick Trick: Check pvPortMalloc result before using pointer [OK]
Common Mistakes:
  • Ignoring NULL check after allocation
  • Confusing memcpy with memmove for this case
  • Thinking immediate free is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes