[asterisk-commits] mjordan: branch 11 r375795 - in /branches/11: ./ main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Nov 3 21:36:59 CDT 2012


Author: mjordan
Date: Sat Nov  3 21:36:55 2012
New Revision: 375795

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=375795
Log:
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
........

Merged revisions 375794 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    branches/11/   (props changed)
    branches/11/main/manager.c

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: branches/11/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/manager.c?view=diff&rev=375795&r1=375794&r2=375795
==============================================================================
--- branches/11/main/manager.c (original)
+++ branches/11/main/manager.c Sat Nov  3 21:36:55 2012
@@ -7257,6 +7257,24 @@
 	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");
+	user->acl = ast_free_acl_list(user->acl);
+	ast_variables_destroy(user->chanvars);
+	ast_free(user);
+}
+
 /*! \internal \brief Clean up resources on Asterisk shutdown */
 static void manager_shutdown(void)
 {
@@ -7299,21 +7317,36 @@
 		ast_manager_unregister("AOCMessage");
 		ast_manager_unregister("Filter");
 		ast_custom_function_unregister(&managerclient_function);
+		ast_cli_unregister_multiple(cli_manager, ARRAY_LEN(cli_manager));
 	}
 
 #ifdef AST_XML_DOCS
 	ao2_t_global_obj_release(event_docs, "Dispose of event_docs");
 #endif
 
+	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) {
 		ao2_ref(sessions, -1);
 		sessions = NULL;
 	}
 
 	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);
 	}
 }
 
@@ -7731,20 +7764,7 @@
 		/* 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");
-		user->acl = ast_free_acl_list(user->acl);
-		ast_variables_destroy(user->chanvars);
-		ast_free(user);
+		manager_free_user(user);
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 




More information about the asterisk-commits mailing list