ESP32 Memory Leak?

Ja, dann ist der Weg wohl nicht so einfach.

Evtl.

  for (const auto &instr : gcode)
  {
    char *gcodeLine = nullptr;
    if (instr.command == "M7" || instr.command == "M8" || instr.command == "M2" || instr.command == "G21" || instr.command == "G90" || instr.command == "F1250")
    {
      gcodeLine = new char[instr.command.length() + 1];
      sprintf(gcodeLine, "%s", instr.command.c_str());
    }
    else
    {
      gcodeLine = new char[20];
      sprintf(gcodeLine, "%s X%.2f Y%.2f", instr.command.c_str(), instr.x, instr.y);
    }
    if (gcodeLine != nullptr) {  // weil Du ja auch keine leere Line pushen willst oder?
      gcodeQueue.push(gcodeLine);
      delete(gcodeLine);
   }
  }

Gruß Tommy