[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to empty a list od type struct list_head



Hi,

Vincenzo Mallozzi wrote:

I'm creating a list of type struct list_head (as I described in previous emails).
Now, I've a doubt regarding the emptying of lists of that type.
I know there are functions like list_del() that delete an element from the list.
Is there a method to empty the whole list or I've to implement such a method by scanning the whole list and deleting each of its element?

A list is composed of elements you've allocated. How can the list management functions know how to free these elements ?


Basically, you have to iterate through the list, delete and free each element. Make sure you use the correct functions to iterate through the list: list_for_each() won't work if you remove elements while iterating. However, list_for_each_safe() will work.

Sincerly,

Thomas
--
Thomas Petazzoni
thomas.petazzoni@xxxxxxxx

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/