Earlier quoted context omitted.
There are so many to choose from. Here is one I just thought up: void free_circularly_linked_list(struct node *head) { struct node *tmp = head; do { struct node *next = tmp->next; free(tmp); tmp = next; } while (tmp != head); } Can you spot the undefined behavior?
The `tmp != head` comparion is UB because `head` is a dangling pointer after the first loop iteration, right?
Let's say head value is "10" and the memory at "10" is {..., next: "10"}
After the first iteration we will have:
Head: "10" Next: "10" Temp: "10"
With "10" pointing to freed memory. But why do we care? We are not dereferencing it, are we?
(I think I am missing something very obvious)