Endlessloop while clearing queue with pointers

I have a structure LastTimeOn that has next pointer to the same structure. I don't want to introduce the back pointer. I am struggling with clearing this structure, can u help me? The program runs in endless loop REM2REM3REM4REM2REM3REM4 etc:

class Pump {
    public:
        LastTimeOn *lastTimeOn;
        Pump();
    };
class LastTimeOn{
    public:
        unsigned int dayOfWeek;
        unsigned int hour;
        unsigned int minute;
        LastTimeOn(unsigned int minute1, unsigned int hour1, unsigned int dayOfWeek1);
        LastTimeOn *next;
    };

    void clearLastTimeOn(Pump *pump1) {
        Serial.print("REM1");
        while (pump1->lastTimeOn != NULL) {
            LastTimeOn *lastTimeOn = pump1->lastTimeOn;
            Serial.print("REM2");
            while (lastTimeOn->next != NULL) {
                Serial.print("REM3");
                
                lastTimeOn = lastTimeOn->next;
    
            }
            Serial.print("REM4");
            delete lastTimeOn;
            if (pump1->lastTimeOn->next == NULL){
                Serial.print("REM4a");
                delete pump1->lastTimeOn;
                pump1->lastTimeOn = NULL;
            }
        }
        Serial.print("REM5");
    }

I create new data like this:

    lastTimeOn->next = new LastTimeOn(minute, hour, dayOfWeek);

arduHenry:
The program runs...

what program?

Your LastTimeOn class doesn't have a destructor, so the compiler created one for you. That one does nothing. When you delete an object, any pointer to the object is NOT set to NULL unless YOU do that. I can't see that you do that.

           delete lastTimeOn;
            if (pump1->lastTimeOn->next == NULL){

You have already deleted the lastTimeOn object, so you can't deference the pointer. Doing so would throw an exception, if the Arduino supported exceptions.

I don't want to introduce the back pointer.

Why not? It makes removing things from linked lists so much easier.

Usually you would introduce a destructor, like this:

class LastTimeOn {
public:
  LastTimeOn(..) { //Constructor
    next = NULL;
  }
  ~LastTimeOn() { //Destructor
    if (next) delete next;
  }
  LastTimeOn *next;
}

Whenever the destructor is invoked, it will destroy the entire chain of nested objects.

Great, the destructor works and simplified the whole code.. Thank you.