diff options
author | Matthew Jordan <mjordan@digium.com> | 2013-05-04 16:00:46 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2013-05-04 16:00:46 +0000 |
commit | 6e2fe0c9ab1ec9cdd0d45e48fd03217d06cc17ae (patch) | |
tree | 6de4bd46b3e2fae5b22734ad076b753aa7c46817 /main/asterisk.c | |
parent | b3bb6608eff9d9ad37eade92cc85506df08655b7 (diff) |
Clean up documentation; prevent ref leak on exit
This patch:
* Cleans up some doxygen
* Prevents leaking the system level Stasis topics and messages
on exit (users of valgrind will be happier)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387633 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/asterisk.c')
-rw-r--r-- | main/asterisk.c | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index 3a1584322..7807ad627 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -417,6 +417,12 @@ struct file_version { char *version; }; +/*! \brief The \ref stasis topic for system level changes */ +static struct stasis_topic *system_topic; + +/*!\ brief The \ref stasis_message_type for network changes */ +static struct stasis_message_type *network_change_type; + static AST_RWLIST_HEAD_STATIC(file_versions, file_version); void ast_register_file_version(const char *file, const char *version) @@ -536,6 +542,42 @@ void ast_unregister_thread(void *id) } } +struct stasis_topic *ast_system_topic(void) +{ + return system_topic; +} + +struct stasis_message_type *ast_network_change_type(void) +{ + return network_change_type; +} + +/*! \brief Cleanup the \ref stasis system level items */ +static void stasis_system_topic_cleanup(void) +{ + ao2_ref(system_topic, -1); + system_topic = NULL; + ao2_ref(network_change_type, -1); + network_change_type = NULL; +} + +/*! \brief Initialize the system level items for \ref stasis */ +static int stasis_system_topic_init(void) +{ + ast_register_atexit(stasis_system_topic_cleanup); + + system_topic = stasis_topic_create("ast_system"); + if (!system_topic) { + return 1; + } + + network_change_type = stasis_message_type_create("network_change"); + if (!network_change_type) { + return -1; + } + return 0; +} + /*! \brief Give an overview of core settings */ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { @@ -3560,26 +3602,6 @@ static void env_init(void) setenv("AST_VERSION", ast_get_version(), 1); } -static struct stasis_topic *system_topic; - -static struct stasis_message_type *network_change_type; - -struct stasis_topic *ast_system_topic(void) -{ - return system_topic; -} - -struct stasis_message_type *ast_network_change_type(void) -{ - return network_change_type; -} - -static void stasis_system_topic_init(void) -{ - system_topic = stasis_topic_create("ast_system"); - network_change_type = stasis_message_type_create("network_change"); -} - static void print_intro_message(const char *runuser, const char *rungroup) { if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) { @@ -4147,7 +4169,10 @@ int main(int argc, char *argv[]) printf("Stasis initialization failed.\n%s", term_quit()); exit(1); } - stasis_system_topic_init(); + if (stasis_system_topic_init()) { + printf("Stasis system-level information initialization failed.\n%s", term_quit()); + exit(1); + } ast_makesocket(); sigemptyset(&sigs); |