diff --git a/libifupdown/dict.c b/libifupdown/dict.c index 3dea682..3f5b1e1 100644 --- a/libifupdown/dict.c +++ b/libifupdown/dict.c @@ -69,7 +69,8 @@ lif_dict_add_once(struct lif_dict *dict, const char *key, void *data, } } - lif_list_free_nodes (&existing); + lif_list_free_nodes(existing); + if (found) return NULL; } diff --git a/libifupdown/list.c b/libifupdown/list.c index 11cfcf5..6ee43fe 100644 --- a/libifupdown/list.c +++ b/libifupdown/list.c @@ -19,21 +19,19 @@ #include "libifupdown/list.h" void -lif_list_free_nodes(struct lif_list **list) +lif_list_free_nodes(struct lif_list *list) { - if (*list == NULL) + if (list == NULL) return; - struct lif_node *iter; + struct lif_node *iter, *iter_next; - LIF_LIST_FOREACH (iter, (*list)->head) + LIF_LIST_FOREACH_SAFE(iter, iter_next, list->head) { - free (iter->prev); + free (iter); } - free (iter); - free (*list); - *list = NULL; + free (list); } void diff --git a/libifupdown/list.h b/libifupdown/list.h index a0155d6..4a495b5 100644 --- a/libifupdown/list.h +++ b/libifupdown/list.h @@ -30,7 +30,7 @@ struct lif_list { size_t length; }; -extern void lif_list_free_nodes(struct lif_list **list); +extern void lif_list_free_nodes(struct lif_list *list); extern void lif_node_insert(struct lif_node *node, void *data, struct lif_list *list); extern void lif_node_insert_tail(struct lif_node *node, void *data, struct lif_list *list);