mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-24 22:58:21 +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:
@@ -957,6 +957,7 @@ static int format_list_add_static(
|
||||
entry->custom_entry = 0;
|
||||
|
||||
ao2_link(format_list, entry);
|
||||
ao2_ref(entry, -1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1025,6 +1026,7 @@ static int build_format_list_array(void)
|
||||
ast_rwlock_unlock(&format_list_array_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int format_list_init(void)
|
||||
{
|
||||
struct ast_format tmpfmt;
|
||||
@@ -1074,6 +1076,20 @@ static int format_list_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! \internal \brief Clean up resources on Asterisk shutdown */
|
||||
static void format_list_shutdown(void)
|
||||
{
|
||||
ast_rwlock_destroy(&format_list_array_lock);
|
||||
if (format_list) {
|
||||
ao2_t_ref(format_list, -1, "Unref format_list container in shutdown");
|
||||
format_list = NULL;
|
||||
}
|
||||
if (format_list_array) {
|
||||
ao2_t_ref(format_list_array, -1, "Unref format_list_array in shutdown");
|
||||
format_list_array = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int ast_format_list_init(void)
|
||||
{
|
||||
if (ast_rwlock_init(&format_list_array_lock)) {
|
||||
@@ -1086,17 +1102,23 @@ int ast_format_list_init(void)
|
||||
goto init_list_cleanup;
|
||||
}
|
||||
|
||||
ast_register_atexit(format_list_shutdown);
|
||||
return 0;
|
||||
init_list_cleanup:
|
||||
|
||||
ast_rwlock_destroy(&format_list_array_lock);
|
||||
ao2_ref(format_list, -1);
|
||||
if (format_list_array) {
|
||||
ao2_ref(format_list_array, -1);
|
||||
}
|
||||
format_list_shutdown();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! \internal \brief Clean up resources on Asterisk shutdown */
|
||||
static void format_attr_shutdown(void)
|
||||
{
|
||||
if (interfaces) {
|
||||
ao2_ref(interfaces, -1);
|
||||
interfaces = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int ast_format_attr_init(void)
|
||||
{
|
||||
ast_cli_register_multiple(my_clis, ARRAY_LEN(my_clis));
|
||||
@@ -1106,6 +1128,7 @@ int ast_format_attr_init(void)
|
||||
if (!interfaces) {
|
||||
return -1;
|
||||
}
|
||||
ast_register_atexit(format_attr_shutdown);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1371,7 +1394,7 @@ int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interf
|
||||
ast_rtp_engine_load_format(&f_list[x].format);
|
||||
}
|
||||
}
|
||||
|
||||
f_list = ast_format_list_destroy(f_list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1405,6 +1428,6 @@ int ast_format_attr_unreg_interface(const struct ast_format_attr_interface *inte
|
||||
|
||||
/* This will remove all custom formats previously created for this interface */
|
||||
load_format_config();
|
||||
|
||||
f_list = ast_format_list_destroy(f_list);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user