changeset 708:a34715d51ea4

Add support for deallocator function in th_cfg_free() for freeing the values.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Apr 2020 00:44:15 +0300
parents 57d30f49fe1e
children 905d30063e45
files th_config.c th_config.h
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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);