Fix invalid memory access in list_clear()