Bird
0
0

Identify the error in the following FreeRTOS code snippet:

medium📝 Debug Q14 of 15
FreeRTOS - Memory Management
Identify the error in the following FreeRTOS code snippet:
void *ptr = pvPortMalloc(50);
// Some code using ptr
vPortFree(ptr);
vPortFree(ptr);
ADouble free of the same pointer
BMissing check if pvPortMalloc returned NULL
CIncorrect function name vPortFree
DMemory leak due to not freeing ptr
Step-by-Step Solution
Solution:
  1. Step 1: Review memory allocation and freeing

    pvPortMalloc(50) allocates memory and returns a pointer stored in ptr. The first vPortFree(ptr) frees this memory.
  2. Step 2: Identify the problem with second free

    The second vPortFree(ptr) attempts to free the same memory again, causing a double free error which can crash or corrupt memory.
  3. Final Answer:

    Double free of the same pointer -> Option A
  4. Quick Check:

    Freeing pointer twice causes error [OK]
Quick Trick: Never free the same pointer twice without resetting it [OK]
Common Mistakes:
  • Ignoring double free risks
  • Not checking for NULL after malloc
  • Confusing function names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes