From 07695ea98a8e65069aa0deb13d30c31f2773f3ae Mon Sep 17 00:00:00 2001 From: aland Date: Thu, 8 Feb 2001 21:11:44 +0000 Subject: [PATCH] Fix a memory leak. If a file is $INCLUDEd, we have a CONF_SECTION data structure for it, which we don't want. We ONLY want the 'children'. So, we re-parent the children, hoist them into the parent CONF_SECTION, and delete the CONF_SECTION for the included file, which is now empty. --- src/main/conffile.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/conffile.c b/src/main/conffile.c index 09ebe95..d58c1c3 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -511,15 +511,35 @@ static CONF_SECTION *cf_section_read(const char *cf, int *lineno, FILE *fp, } /* - * Add the included conf to our CONF_SECTION - */ + * Add the included conf to our CONF_SECTION + */ if (is != NULL) { if (is->children != NULL) { - cf_item_add(cs, is->children); - } else { - /* the file was empty */ - cf_section_free(&is); + CONF_ITEM *ci; + + /* + * Re-write the parent of the + * moved children to be the + * upper-layer section. + */ + for (ci = is->children; ci; ci = ci->next) { + ci->parent = cs; + } + + /* + * If there are children, then + * move them up a layer. + */ + if (is->children) { + cf_item_add(cs, is->children); + } + is->children = NULL; } + /* + * Always free the section for the + * $INCLUDEd file. + */ + cf_section_free(&is); } continue; @@ -1083,8 +1103,8 @@ CONF_SECTION *cf_section_find(const char *name) CONF_SECTION *cf_section_sub_find(CONF_SECTION *section, const char *name) { - CONF_ITEM *ci; + for (ci = section->children; ci; ci = ci->next) { if (ci->type != CONF_ITEM_SECTION) continue; -- 2.1.4