diff --git a/du4/a_train.c b/du4/a_train.c index 3c99d33..c7bb6fd 100644 --- a/du4/a_train.c +++ b/du4/a_train.c @@ -68,11 +68,16 @@ struct car* clear_train(struct car* first, const char* target) { prev = temp; temp = temp->next; if(strcmp(temp->value, target) == 0){ - struct car* next = temp->next; - prev->next = next; - temp = next; + struct car* targetNode = temp; + prev->next = temp->next; + temp = temp->next; + free(targetNode); } + else{ + prev = temp; + temp = temp->next; + } }