From 4df92783284eca3950cc78c6c78e522098074110 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Sun, 1 May 2005 20:45:07 +0000 Subject: reimplemented list_free() a safer way --- src/pacman/list.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/pacman/list.c b/src/pacman/list.c index c639e124..1d32b0b8 100644 --- a/src/pacman/list.c +++ b/src/pacman/list.c @@ -45,17 +45,14 @@ list_t *list_new() void list_free(list_t *list) { - if(list == NULL) { - return; - } - if(list->data != NULL) { - free(list->data); - list->data = NULL; - } - if(list->next != NULL) { - list_free(list->next); + list_t *ptr, *it = list; + + while(it) { + ptr = it->next; + free(it->data); + free(it); + it = ptr; } - free(list); return; } -- cgit v1.2.3-24-g4f1b