src/server/config/conf.c

changeset 79
f48cea237ec3
parent 51
b28cf69f42e8
child 83
28433f06d5ee
--- a/src/server/config/conf.c	Tue Jun 25 22:18:59 2013 +0200
+++ b/src/server/config/conf.c	Wed Jun 26 15:09:54 2013 +0200
@@ -51,7 +51,12 @@
         line->line = sstrdup_mp(parser->mp, l); // TODO: check for 0-len str
         line->object = NULL;
         line->type = LINE_OTHER;
-        parser->lines = ucx_dlist_append(parser->lines, line);
+        if(parser->lines) {
+            parser->lines = ucx_dlist_append(parser->lines, line);
+        } else {
+            parser->lines = ucx_dlist_append(parser->lines, line);
+            cfg_dlist_destr(parser->mp, parser->lines);
+        }
 
         // check if the line contains something
         l = cfg_trim_comment(l);
@@ -107,6 +112,7 @@
                 }
 
                 if(r != 0) {
+                    free(org_ptr);
                     return -1;
                 }
             }
@@ -353,8 +359,9 @@
         }
 
         // add param to list
-        plist = ucx_list_append(plist, param); // TODO: use mp
+        plist = ucx_list_append(plist, param);
     }
+    cfg_list_destr(mp, plist);
     return plist;
 }
 
@@ -525,7 +532,12 @@
         }
 
         // add param to list
-        tag->param = ucx_list_append(tag->param, param);
+        if(tag->param) {
+            tag->param = ucx_list_append(tag->param, param);
+        } else {
+            tag->param = ucx_list_append(tag->param, param);
+            cfg_list_destr(mp, tag->param);
+        }
     }
 
     return tag;
@@ -582,3 +594,51 @@
 }
 */
 
+static void cfg_list_free(void *list) {
+    ucx_list_free(list);
+}
+static void cfg_dlist_free(void *dlist) {
+    ucx_dlist_free(dlist);
+}
+static void cfg_map_free(void *map) {
+    ucx_map_free(map);
+}
+
+void cfg_list_destr(UcxMempool *mp, UcxList *list) {
+    if(list) {
+        ucx_mempool_reg_destr(mp, list, cfg_list_free);
+    }
+}
+
+void cfg_dlist_destr(UcxMempool *mp, UcxDlist *dlist) {
+    if(dlist) {
+        ucx_mempool_reg_destr(mp, dlist, cfg_dlist_free);
+    }
+}
+
+void cfg_map_destr(UcxMempool *mp, UcxMap *map) {
+    if(map) {
+        ucx_mempool_reg_destr(mp, map, cfg_map_free);
+    }
+}
+
+UcxList* cfg_list_append(UcxMempool *mp, UcxList *list, void *data) {
+    if(list) {
+        return ucx_list_append(list, data);
+    } else {
+        UcxList *r = ucx_list_append(list, data);
+        cfg_list_destr(mp, r);
+        return r;
+    }
+}
+
+UcxDlist* cfg_dlist_append(UcxMempool *mp, UcxDlist *list, void *data) {
+    if(list) {
+        return ucx_dlist_append(list, data);
+    } else {
+        UcxDlist *r = ucx_dlist_append(list, data);
+        cfg_dlist_destr(mp, r);
+        return r;
+    }
+}
+

mercurial