conffile: cleanup section children and tail on data remove
authorAleksey Katargin <gureedo@intersvyaz.net>
Wed, 19 Oct 2016 08:05:11 +0000 (13:05 +0500)
committerAleksey Katargin <gureedo@intersvyaz.net>
Wed, 19 Oct 2016 08:09:09 +0000 (13:09 +0500)
Signed-off-by: Aleksey Katargin <gureedo@intersvyaz.net>
src/main/conffile.c

index 611c386..df78184 100644 (file)
@@ -3624,6 +3624,7 @@ void *cf_data_remove(CONF_SECTION *cs, char const *name)
 {
        CONF_DATA mycd;
        CONF_DATA *cd;
+       CONF_ITEM *ci, *it;
        void *data;
 
        if (!cs || !name) return NULL;
@@ -3637,6 +3638,20 @@ void *cf_data_remove(CONF_SECTION *cs, char const *name)
        cd = rbtree_finddata(cs->data_tree, &mycd);
        if (!cd) return NULL;
 
+       ci = cf_data_to_item(cd);
+       if (cs->children == ci) {
+               cs->children = ci->next;
+               if (cs->tail == ci) cs->tail = NULL;
+       } else {
+               for (it = cs->children; it; it = it->next) {
+                       if (it->next == ci) {
+                               it->next = ci->next;
+                               if (cs->tail == ci) cs->tail = it;
+                               break;
+                       }
+               }
+       }
+
        talloc_set_destructor(cd, NULL);        /* Disarm the destructor */
        rbtree_deletebydata(cs->data_tree, &mycd);