aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/args.c5
-rw-r--r--lib/lib.h2
-rw-r--r--lib/llist.c9
3 files changed, 9 insertions, 7 deletions
diff --git a/lib/args.c b/lib/args.c
index f4ceba1e..e3dcb26e 100644
--- a/lib/args.c
+++ b/lib/args.c
@@ -413,4 +413,9 @@ notflag:
if (toys.optc>gof.maxargs)
error_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]);
if (CFG_HELP) toys.exithelp = 0;
+
+ if (CFG_TOYBOX_FREE) {
+ llist_traverse(gof.opts, free);
+ llist_traverse(gof.longopts, free);
+ }
}
diff --git a/lib/lib.h b/lib/lib.h
index 4c230092..8028737e 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -35,7 +35,7 @@ struct double_list {
char *data;
};
-void llist_free(void *list, void (*freeit)(void *data));
+void llist_traverse(void *list, void (*using)(void *data));
void *llist_pop(void *list); // actually void **list, but the compiler's dumb
void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
struct double_list *dlist_add(struct double_list **list, char *data);
diff --git a/lib/llist.c b/lib/llist.c
index 8588721b..4799db1c 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -6,15 +6,12 @@
#include "toys.h"
-// Free all the elements of a linked list
-// if freeit!=NULL call freeit() on each element before freeing it.
-
-void llist_free(void *list, void (*freeit)(void *data))
+// Call a function (such as free()) on each element of a linked list.
+void llist_traverse(void *list, void (*using)(void *data))
{
while (list) {
void *pop = llist_pop(&list);
- if (freeit) freeit(pop);
- else free(pop);
+ using(pop);
// End doubly linked list too.
if (list==pop) break;