Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 375799) +++ main/asterisk.c (working copy) @@ -1737,6 +1740,7 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart) { + int active_channels; if (niceness >= SHUTDOWN_NICE) { ast_module_shutdown(); } @@ -1763,13 +1767,14 @@ } } } + active_channels = ast_active_channels(); /* The manager event for shutdown must happen prior to ast_run_atexits, as * the manager interface will dispose of its sessions as part of its * shutdown. */ manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\n" "Restart: %s\r\n", - ast_active_channels() ? "Uncleanly" : "Cleanly", + active_channels ? "Uncleanly" : "Cleanly", restart ? "True" : "False"); if (option_verbose) @@ -1777,7 +1782,7 @@ ast_run_atexits(); /* Called on exit */ if (option_verbose && ast_opt_console) - ast_verbose("Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num); + ast_verbose("Asterisk %s ending (%d).\n", active_channels ? "uncleanly" : "cleanly", num); ast_debug(1, "Asterisk ending (%d).\n", num); if (ast_socket > -1) { pthread_cancel(lthread); @@ -1804,6 +1809,7 @@ /* close logger */ close_logger(); + clean_zones(); /* If there is a consolethread running send it a SIGHUP so it can execvp, otherwise we can do it ourselves */ @@ -1817,6 +1823,7 @@ } else { /* close logger */ close_logger(); + clean_zones(); } exit(0); @@ -3302,6 +3309,10 @@ setenv("AST_VERSION", ast_get_version(), 1); } +static void main_atexit(void) { + ast_cli_unregister_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk)); +} + int main(int argc, char *argv[]) { int c; @@ -3987,6 +3998,7 @@ ast_lastreloadtime = ast_startuptime = ast_tvnow(); ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk)); + ast_register_atexit(main_atexit); run_startup_commands(); Index: include/asterisk/_private.h =================================================================== --- include/asterisk/_private.h (revision 375799) +++ include/asterisk/_private.h (working copy) @@ -19,6 +19,7 @@ int load_pbx(void); /*!< Provided by pbx.c */ int init_logger(void); /*!< Provided by logger.c */ void close_logger(void); /*!< Provided by logger.c */ +void clean_zones(void); /*!< Provided by localtime.c */ int init_framer(void); /*!< Provided by frame.c */ int ast_term_init(void); /*!< Provided by term.c */ int astdb_init(void); /*!< Provided by db.c */ Index: main/stdtime/localtime.c =================================================================== --- main/stdtime/localtime.c (revision 375799) +++ main/stdtime/localtime.c (working copy) @@ -71,6 +71,7 @@ #include "private.h" #include "tzfile.h" +#include "asterisk/_private.h" #include "asterisk/lock.h" #include "asterisk/localtime.h" #include "asterisk/strings.h" @@ -1410,6 +1411,16 @@ return -1; } +void clean_zones(void) { + struct state *sp; + AST_LIST_LOCK(&zonelist); + while ((sp = AST_LIST_LAST(&zonelist))) { + AST_LIST_REMOVE(&zonelist, sp, list); + ast_free(sp); + } + AST_LIST_UNLOCK(&zonelist); +} + static const struct state *ast_tzset(const char *zone) { struct state *sp;