aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.h2
-rw-r--r--lib/llist.c8
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/lib.h b/lib/lib.h
index cfbeeb3a..70c0c48d 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -27,7 +27,7 @@ struct double_list {
void llist_free(void *list, void (*freeit)(void *data));
void *llist_pop(void *list); // actually void **list, but the compiler's dumb
-void dlist_add(struct double_list **list, char *data);
+struct double_list *dlist_add(struct double_list **list, char *data);
// args.c
void get_optflags(void);
diff --git a/lib/llist.c b/lib/llist.c
index 4f9bc220..9adb64e0 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -14,6 +14,10 @@ void llist_free(void *list, void (*freeit)(void *data))
while (list) {
void *pop = llist_pop(&list);
if (freeit) freeit(pop);
+ else free(pop);
+
+ // End doubly linked list too.
+ if (list==pop) break;
}
}
@@ -32,7 +36,7 @@ void *llist_pop(void *list)
}
// Add an entry to the end off a doubly linked list
-void dlist_add(struct double_list **list, char *data)
+struct double_list *dlist_add(struct double_list **list, char *data)
{
struct double_list *line = xmalloc(sizeof(struct double_list));
@@ -43,4 +47,6 @@ void dlist_add(struct double_list **list, char *data)
(*list)->prev->next = line;
(*list)->prev = line;
} else *list = line->next = line->prev = line;
+
+ return line;
}