From 3ec36c1f5135242fc47587665d506877ecfdd606 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 17 Mar 2007 15:06:33 +0000 Subject: [PATCH] improve reloadxml code to fix potential issue git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4630 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_xml.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/switch_xml.c b/src/switch_xml.c index 4641c09e36..fac8c495be 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1083,37 +1083,40 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_root(void) SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err) { char path_buf[1024]; - uint8_t hasmain = 0; - + uint8_t hasmain = 0, errcnt = 0; + switch_xml_t new_main; + switch_mutex_lock(XML_LOCK); if (MAIN_XML_ROOT) { - switch_xml_t xml; hasmain++; if (!reload) { switch_mutex_unlock(XML_LOCK); return switch_xml_root(); } - xml = MAIN_XML_ROOT; - MAIN_XML_ROOT = NULL; switch_thread_rwlock_wrlock(RWLOCK); - switch_xml_free(xml); } snprintf(path_buf, sizeof(path_buf), "%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, "freeswitch.xml"); - if ((MAIN_XML_ROOT = switch_xml_parse_file(path_buf))) { - *err = switch_xml_error(MAIN_XML_ROOT); + if ((new_main = switch_xml_parse_file(path_buf))) { + *err = switch_xml_error(new_main); if (!switch_strlen_zero(*err)) { - switch_xml_free(MAIN_XML_ROOT); - MAIN_XML_ROOT = NULL; + switch_xml_free(new_main); + new_main = NULL; + errcnt++; } else { + switch_xml_t old_root; *err = "Success"; + old_root = MAIN_XML_ROOT; + MAIN_XML_ROOT = new_main; switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT); + switch_xml_free(old_root); } } else { *err = "Cannot Open log directory or XML Root!"; + errcnt++; } if (hasmain) { @@ -1121,7 +1124,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e } switch_mutex_unlock(XML_LOCK); - return switch_xml_root(); + return errcnt == 0 ? switch_xml_root() : NULL; }