rewrote list_free to not be recursive anymore
(it can trigger segmentation faults when freeing long lists)
This commit is contained in:
parent
7767095c59
commit
03f2ec2d0b
1 changed files with 7 additions and 11 deletions
|
@ -68,18 +68,14 @@ PMList* pm_list_new()
|
|||
|
||||
void pm_list_free(PMList *list)
|
||||
{
|
||||
if(list == NULL) {
|
||||
return;
|
||||
PMList *ptr, *it = list;
|
||||
|
||||
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) {
|
||||
pm_list_free(list->next);
|
||||
}
|
||||
free(list);
|
||||
return;
|
||||
}
|
||||
|
||||
PMList* pm_list_add(PMList *list, void *data)
|
||||
|
|
Loading…
Add table
Reference in a new issue