mirror of
https://github.com/moparisthebest/pacman
synced 2024-10-31 15:45:03 -04:00
reimplemented list_free() a safer way
This commit is contained in:
parent
a73427fc0b
commit
4df9278328
@ -45,17 +45,14 @@ list_t *list_new()
|
|||||||
|
|
||||||
void list_free(list_t *list)
|
void list_free(list_t *list)
|
||||||
{
|
{
|
||||||
if(list == NULL) {
|
list_t *ptr, *it = list;
|
||||||
return;
|
|
||||||
|
while(it) {
|
||||||
|
ptr = it->next;
|
||||||
|
free(it->data);
|
||||||
|
free(it);
|
||||||
|
it = ptr;
|
||||||
}
|
}
|
||||||
if(list->data != NULL) {
|
|
||||||
free(list->data);
|
|
||||||
list->data = NULL;
|
|
||||||
}
|
|
||||||
if(list->next != NULL) {
|
|
||||||
list_free(list->next);
|
|
||||||
}
|
|
||||||
free(list);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user