# HG changeset patch # User Matti Hamalainen # Date 1587937455 -10800 # Node ID a34715d51ea4179ab22d8ed80431d821982c349e # Parent 57d30f49fe1e093bcbab3a00d2715fecba2da1f3 Add support for deallocator function in th_cfg_free() for freeing the values. diff -r 57d30f49fe1e -r a34715d51ea4 th_config.c --- a/th_config.c Mon Apr 27 00:43:20 2020 +0300 +++ b/th_config.c Mon Apr 27 00:44:15 2020 +0300 @@ -15,9 +15,10 @@ #define SET_MAX_BUF (8192) -/* Free a given configuration (the values are not free'd) +/* Deallocate a given configuration. Notice that the values are NOT freed, + * unless a deallocator function is specified to free them. */ -void th_cfg_free(th_cfgitem_t *cfg) +void th_cfg_free(th_cfgitem_t *cfg, void (*freefunc)(th_cfgitem_t *)) { th_cfgitem_t *node = cfg; @@ -26,7 +27,10 @@ th_cfgitem_t *next = (th_cfgitem_t *) node->node.next; if (node->type == ITEM_SECTION) - th_cfg_free((th_cfgitem_t *) node->v.data); + th_cfg_free((th_cfgitem_t *) node->v.data, freefunc); + else + if (freefunc != NULL) + freefunc(node); th_free(node->name); th_free(node); diff -r 57d30f49fe1e -r a34715d51ea4 th_config.h --- a/th_config.h Mon Apr 27 00:43:20 2020 +0300 +++ b/th_config.h Mon Apr 27 00:44:15 2020 +0300 @@ -63,7 +63,7 @@ // Functions // int th_cfg_read(th_ioctx *fh, th_cfgitem_t *cfg /*, TODO XXX const int flags (for controlling things like "error out on unknown items or ignore" etc */); -void th_cfg_free(th_cfgitem_t *cfg); +void th_cfg_free(th_cfgitem_t *cfg, void (*freefunc)(th_cfgitem_t *)); int th_cfg_write(th_ioctx *fh, const th_cfgitem_t *cfg); int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment);