diff --git a/cfg_pp.c b/cfg_pp.c index 7f88cf76bad..44fb3ebc18f 100644 --- a/cfg_pp.c +++ b/cfg_pp.c @@ -57,6 +57,7 @@ static int exec_preprocessor(FILE *flat_cfg, const char *preproc_cmdline, str *out); static struct cfg_context *cfg_context_new_file(const char *path); +static void cfg_context_reset_all(void); static void cfg_context_append_line(struct cfg_context *con, char *line, int len); @@ -82,6 +83,8 @@ int parse_opensips_cfg(const char *cfg_file, const char *preproc_cmdline, } } + cfg_context_reset_all(); + if (flatten_opensips_cfg(cfg_stream, cfg_stream == stdin ? "stdin" : cfg_file, &cfg_buf) < 0) { LM_ERR("failed to resolve file imports for %s\n", cfg_file); @@ -248,6 +251,21 @@ static struct cfg_context { struct cfg_context *next; } *__ccon; +static void cfg_context_reset_all(void) +{ + struct cfg_context *pos = NULL, *it = __ccon; + + while ( it && (it != __ccon || !pos) ) { + pos = it; + it = it->next; + free((char*)pos->path); + free((char*)pos->dirname); + free(pos->lines); + free(pos); + }; + __ccon = NULL; +} + static struct cfg_context *cfg_context_new_file(const char *path) { struct cfg_context *con, *it;