summaryrefslogtreecommitdiff
path: root/main/pbx.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/pbx.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/pbx.c')
-rw-r--r--main/pbx.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/main/pbx.c b/main/pbx.c
index 6c1fbcdbb..1e8f1a33b 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -11488,6 +11488,32 @@ static const struct ast_data_entry pbx_data_providers[] = {
AST_DATA_ENTRY("asterisk/core/hints", &hints_data_provider),
};
+/*! \internal \brief Clean up resources on Asterisk shutdown.
+ * \note Cleans up resources allocated in load_pbx */
+static void unload_pbx(void)
+{
+ int x;
+
+ if (presence_state_sub) {
+ presence_state_sub = ast_event_unsubscribe(presence_state_sub);
+ }
+ if (device_state_sub) {
+ device_state_sub = ast_event_unsubscribe(device_state_sub);
+ }
+
+ /* Unregister builtin applications */
+ for (x = 0; x < ARRAY_LEN(builtins); x++) {
+ ast_unregister_application(builtins[x].name);
+ }
+ ast_manager_unregister("ShowDialPlan");
+ ast_custom_function_unregister(&exception_function);
+ ast_custom_function_unregister(&testtime_function);
+ ast_data_unregister(NULL);
+ if (extension_state_tps) {
+ extension_state_tps = ast_taskprocessor_unreference(extension_state_tps);
+ }
+}
+
int load_pbx(void)
{
int x;
@@ -11526,6 +11552,7 @@ int load_pbx(void)
return -1;
}
+ ast_register_atexit(unload_pbx);
return 0;
}
@@ -11886,11 +11913,26 @@ static int statecbs_cmp(void *obj, void *arg, int flags)
return (state_cb->change_cb == change_cb) ? CMP_MATCH | CMP_STOP : 0;
}
+/*! \internal \brief Clean up resources on Asterisk shutdown */
+static void pbx_shutdown(void)
+{
+ if (hints) {
+ ao2_ref(hints, -1);
+ }
+ if (hintdevices) {
+ ao2_ref(hintdevices, -1);
+ }
+ if (statecbs) {
+ ao2_ref(statecbs, -1);
+ }
+}
+
int ast_pbx_init(void)
{
hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
hintdevices = ao2_container_alloc(HASH_EXTENHINT_SIZE, hintdevice_hash_cb, hintdevice_cmp_multiple);
statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
+ ast_register_atexit(pbx_shutdown);
return (hints && hintdevices && statecbs) ? 0 : -1;
}