From: Automerge script Date: Sun, 4 Nov 2012 03:25:02 +0000 (+0000) Subject: Merged revisions 375794,375797,375801 via svnmerge from X-Git-Tag: 10.11.0-digiumphones-rc1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5b13b3893d3b47a25c15794bb1603b6eb907aa7;p=thirdparty%2Fasterisk.git Merged revisions 375794,375797,375801 via svnmerge from file:///srv/subversion/repos/asterisk/branches/10 ................ r375794 | mjordan | 2012-11-03 21:30:30 -0500 (Sat, 03 Nov 2012) | 15 lines Properly clean up manager resources on exit This patch does two things: 1) It properly unregisters the manager CLI commands 2) It cleans up AMI users on exit. Prior to this patch, the AMI users were not being disposed of properly, resulting in a memory leak. (closes issue ASTERISK-20646) Reported by: Corey Farrell patches: manager_shutdown.patch uploaded by Corey Farrell (license 5909) ........ Merged revisions 375793 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ................ r375797 | mjordan | 2012-11-03 21:42:43 -0500 (Sat, 03 Nov 2012) | 9 lines Only deref a reserved gateway session if we actually reserved one Its perfectly acceptable to have a gateway session unreserved when we go to first allocate one. Unreffing the reserved gateway session - when its NULL - will result in an assertion error. This problem was caught by the Asterisk Test Suite (once we had enough of the debugging flags enabled) ................ r375801 | mjordan | 2012-11-03 22:08:12 -0500 (Sat, 03 Nov 2012) | 17 lines Don't attempt to purge sessions when no sessions exist Manager's tcp/tls objects have a periodic function that purge old manager sessions periodically. During shutdown, the underlying container holding those sessions can be disposed of and set to NULL before the tcp/tls periodic function is stopped. If the periodic function fires, it will attempt to iterate over a NULL container. This patch checks for whether or not the sessions container exists before attempting to purge sessions out of it. If the sessions container is NULL, we simply return. Note that this error was also caught by the Asterisk Test Suite. ........ Merged revisions 375800 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10-digiumphones@375828 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/manager.c b/main/manager.c index a8e48c25e0..9a67cce682 100644 --- a/main/manager.c +++ b/main/manager.c @@ -5225,6 +5225,10 @@ static void purge_sessions(int n_max) time_t now = time(NULL); struct ao2_iterator i; + if (!sessions) { + return; + } + i = ao2_iterator_init(sessions, 0); while ((session = ao2_iterator_next(&i)) && n_max > 0) { ao2_lock(session); @@ -6771,6 +6775,23 @@ static void load_channelvars(struct ast_variable *var) AST_RWLIST_UNLOCK(&channelvars); } +/*! \internal \brief Free a user record. Should already be removed from the list */ +static void manager_free_user(struct ast_manager_user *user) +{ + if (user->a1_hash) { + ast_free(user->a1_hash); + } + if (user->secret) { + ast_free(user->secret); + } + ao2_t_callback(user->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters"); + ao2_t_callback(user->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters"); + ao2_t_ref(user->whitefilters, -1, "decrement ref for white container, should be last one"); + ao2_t_ref(user->blackfilters, -1, "decrement ref for black container, should be last one"); + ast_free_ha(user->ha); + ast_free(user); +} + /*! \internal \brief Clean up resources on Asterisk shutdown */ static void manager_shutdown(void) { @@ -6811,6 +6832,23 @@ static void manager_shutdown(void) ast_manager_unregister("ModuleCheck"); ast_manager_unregister("AOCMessage"); ast_manager_unregister("Filter"); + ast_cli_unregister_multiple(cli_manager, ARRAY_LEN(cli_manager)); + } + + ast_tcptls_server_stop(&ami_desc); + ast_tcptls_server_stop(&amis_desc); + + if (ami_tls_cfg.certfile) { + ast_free(ami_tls_cfg.certfile); + ami_tls_cfg.certfile = NULL; + } + if (ami_tls_cfg.pvtfile) { + ast_free(ami_tls_cfg.pvtfile); + ami_tls_cfg.pvtfile = NULL; + } + if (ami_tls_cfg.cipher) { + ast_free(ami_tls_cfg.cipher); + ami_tls_cfg.cipher = NULL; } if (sessions) { @@ -6819,13 +6857,10 @@ static void manager_shutdown(void) } while ((user = AST_LIST_REMOVE_HEAD(&users, list))) { - ao2_ref(user->whitefilters, -1); - ao2_ref(user->blackfilters, -1); - ast_free(user); + manager_free_user(user); } } - static int __init_manager(int reload) { struct ast_config *ucfg = NULL, *cfg = NULL; @@ -7182,19 +7217,7 @@ static int __init_manager(int reload) /* We do not need to keep this user so take them out of the list */ AST_RWLIST_REMOVE_CURRENT(list); ast_debug(4, "Pruning user '%s'\n", user->username); - /* Free their memory now */ - if (user->a1_hash) { - ast_free(user->a1_hash); - } - if (user->secret) { - ast_free(user->secret); - } - ao2_t_callback(user->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters"); - ao2_t_callback(user->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters"); - ao2_t_ref(user->whitefilters, -1, "decrement ref for white container, should be last one"); - ao2_t_ref(user->blackfilters, -1, "decrement ref for black container, should be last one"); - ast_free_ha(user->ha); - ast_free(user); + manager_free_user(user); } AST_RWLIST_TRAVERSE_SAFE_END; diff --git a/res/res_fax.c b/res/res_fax.c index 3bec8b6665..836973829f 100644 --- a/res/res_fax.c +++ b/res/res_fax.c @@ -2549,7 +2549,9 @@ static int fax_gateway_start(struct fax_gateway *gateway, struct ast_fax_session } /* release the reference for the reserved session and replace it with * the real session */ - ao2_ref(gateway->s, -1); + if (gateway->s) { + ao2_ref(gateway->s, -1); + } gateway->s = s; gateway->token = NULL;