diff th_config.c @ 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 ae601363fdad
children 4ca6a3b30fe8
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);