Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 375921) +++ main/asterisk.c (working copy) @@ -1757,6 +1757,7 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart) { + int active_channels; if (niceness >= SHUTDOWN_NICE) { ast_module_shutdown(); } @@ -1783,6 +1784,7 @@ } } } + 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. @@ -1808,13 +1810,13 @@ ***/ 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"); ast_verb(0, "Executing last minute cleanups\n"); ast_run_atexits(); /* Called on exit */ - ast_verb(0, "Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num); + ast_verb(0, "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); @@ -1839,6 +1841,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 */ @@ -1852,6 +1855,7 @@ } else { /* close logger */ close_logger(); + clean_zones(); } exit(0); @@ -3440,6 +3444,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; @@ -4147,6 +4155,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: main/stdtime/localtime.c =================================================================== --- main/stdtime/localtime.c (revision 375921) +++ 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" @@ -1436,6 +1437,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; Index: include/asterisk/_private.h =================================================================== --- include/asterisk/_private.h (revision 375921) +++ 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 */