mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-19 19:20:35 +00:00
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
This commit is contained in:
42
main/pbx.c
42
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user