From 41d57ac56d7ef648f270bb22315cfc8f07c607ab Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Mon, 1 Nov 2021 17:21:46 +0200 Subject: [PATCH] [core] fix printing cfg file context for errors after a reload_routes Reset the file context list each time a new cfg parsing starts, to be sure we do not inherite the context from a previous parsing. If we do not do this, when doing a reload_routes, if an parsing error occurs, we will get references and dumps (of the faulty lines) from the original, startup script, not from the reloaded one. (cherry picked from commit 52e51809ca219c97ea9e348f5dab6a109859eece) --- cfg_pp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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;