2
I am in doubt in the implementation of the method of releasing the memory of a circular chained list:
void liberarLista() {
if(head == NULL)
return; //retorna original(NULL);
lista *aux, *temp = head;
while(temp->prox != head) {
aux = temp;
temp = temp->prox;
free(aux);
}
head = NULL;
}
In the material I’m reading it releases after the while
the head
, but it occurs segmentatium fault
, but I don’t know if it’s necessary since the aux
releases the first node (head
);
After the first iteration of your while will already generate an error as you try to access the memory address pointed by Head, however it no longer exists as it has just been released.
– Nayron Morais
Add more information so we can help
– Nayron Morais