why this does not cause memory leak
struct node {
    int val;
    struct node *next;
};
void free_list(struct node *head) {
    while (head != NULL) {
        free(head);
        head = head->next;
    }