31. Dynamic Memory Allocation-ii

Question.6

A firmware code review finds this in a long-running IoT device:

void handle_mqtt() {
   char* payload = new char[msg_len];
   decode(payload, msg_len);
   if (error) return;  // <-- LEAK!
   delete[] payload;
}

What is the bug?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!