list: refactor lif_list_free_nodes() a bit

This commit is contained in:
Ariadne Conill 2020-07-28 17:53:48 -04:00
parent 58816712c6
commit cfbfa07e85
3 changed files with 9 additions and 10 deletions

View file

@ -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) if (found)
return NULL; return NULL;
} }

View file

@ -19,21 +19,19 @@
#include "libifupdown/list.h" #include "libifupdown/list.h"
void void
lif_list_free_nodes(struct lif_list **list) lif_list_free_nodes(struct lif_list *list)
{ {
if (*list == NULL) if (list == NULL)
return; 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);
free (*list);
*list = NULL;
} }
void void

View file

@ -30,7 +30,7 @@ struct lif_list {
size_t length; 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(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); extern void lif_node_insert_tail(struct lif_node *node, void *data, struct lif_list *list);