| Add clearitem() to recursively free a dir item - sacc - sacc(omys), simple cons… | |
| git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
| Log | |
| Files | |
| Refs | |
| Tags | |
| LICENSE | |
| --- | |
| commit da486e90d17187e1fe8d8ed26982840059aaf968 | |
| parent 97eaeb752ee3fd28ac14199692a5082e257ef10e | |
| Author: Quentin Rameau <[email protected]> | |
| Date: Tue, 11 Jul 2017 10:31:38 +0200 | |
| Add clearitem() to recursively free a dir item | |
| Diffstat: | |
| M common.h | 2 ++ | |
| M sacc.c | 23 ++++++++++++++++++++++- | |
| 2 files changed, 24 insertions(+), 1 deletion(-) | |
| --- | |
| diff --git a/common.h b/common.h | |
| @@ -1,3 +1,5 @@ | |
| +#define clear(p) do { void **_p = (void **)(p); free(*_p); *_p = NULL; … | |
| + | |
| typedef struct item Item; | |
| typedef struct dir Dir; | |
| diff --git a/sacc.c b/sacc.c | |
| @@ -91,6 +91,26 @@ usage(void) | |
| die("usage: sacc URL"); | |
| } | |
| +static void | |
| +clearitem(Item *item) | |
| +{ | |
| + Dir *dir = item->dir; | |
| + Item **items; | |
| + size_t i; | |
| + | |
| + if (dir) { | |
| + items = dir->items; | |
| + for (i = 0; i < dir->nitems; ++i) { | |
| + clearitem(items[i]); | |
| + free(items[i]); | |
| + } | |
| + free(items); | |
| + clear(&item->dir); | |
| + } | |
| + | |
| + clear(&item->raw); | |
| +} | |
| + | |
| const char * | |
| typedisplay(char t) | |
| { | |
| @@ -559,7 +579,8 @@ moldentry(char *url) | |
| static void | |
| cleanup(void) | |
| { | |
| - free(mainentry); /* TODO free all tree recursively */ | |
| + clearitem(mainentry); | |
| + free(mainentry); | |
| free(mainurl); | |
| uicleanup(); | |
| } |