summaryrefslogtreecommitdiff
path: root/main/message.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-10-02 01:47:16 +0000
committerMatthew Jordan <mjordan@digium.com>2012-10-02 01:47:16 +0000
commita094707d5156a005fb6e9277bd4a14f9d7e7ab1c (patch)
tree26a15c7ef864995e2f2d89d09294024bad0145cb /main/message.c
parent4e228fce0382550136e5c34cb4d9fd400b8d4ad3 (diff)
Fix a variety of ref counting issues
This patch resolves a number of ref leaks that occur primarily on Asterisk shutdown. It adds a variety of shutdown routines to core portions of Asterisk such that they can reclaim resources allocate duringd initialization. Review: https://reviewboard.asterisk.org/r/2137 ........ Merged revisions 374177 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 374178 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 374196 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@374197 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/message.c')
-rw-r--r--main/message.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/main/message.c b/main/message.c
index c04413dc8..f764e2774 100644
--- a/main/message.c
+++ b/main/message.c
@@ -1302,6 +1302,30 @@ int ast_msg_tech_unregister(const struct ast_msg_tech *tech)
return 0;
}
+void ast_msg_shutdown()
+{
+ if (msg_q_tp) {
+ msg_q_tp = ast_taskprocessor_unreference(msg_q_tp);
+ }
+}
+
+/*! \internal \brief Clean up other resources on Asterisk shutdown
+ * \note This does not include the msg_q_tp object, which must be disposed
+ * of prior to Asterisk checking for channel destruction in its shutdown
+ * sequence. The atexit handlers are executed after this occurs. */
+static void message_shutdown(void)
+{
+ ast_custom_function_unregister(&msg_function);
+ ast_custom_function_unregister(&msg_data_function);
+ ast_unregister_application(app_msg_send);
+ ast_manager_unregister("MessageSend");
+
+ if (msg_techs) {
+ ao2_ref(msg_techs, -1);
+ msg_techs = NULL;
+ }
+}
+
/*
* \internal
* \brief Initialize stuff during Asterisk startup.
@@ -1331,10 +1355,7 @@ int ast_msg_init(void)
res |= ast_register_application2(app_msg_send, msg_send_exec, NULL, NULL, NULL);
res |= ast_manager_register_xml_core("MessageSend", EVENT_FLAG_MESSAGE, action_messagesend);
- return res;
-}
+ ast_register_atexit(message_shutdown);
-void ast_msg_shutdown(void)
-{
- msg_q_tp = ast_taskprocessor_unreference(msg_q_tp);
+ return res;
}