[asterisk-commits] jrose: branch 1.8 r401829 - /branches/1.8/main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 24 15:32:39 CDT 2013


Author: jrose
Date: Thu Oct 24 15:32:37 2013
New Revision: 401829

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=401829
Log:
utils: Fix memory leaks and missed unregistration of CLI commands  on shutdown

Final set of patches in a series of memory leak/cleanup patches by Corey Farrell

(closes issue ASTERISK-22467)
Reported by: Corey Farrell
Patches:
    main-utils-1.8.patch uploaded by coreyfarrell (license 5909)
    main-utils-11.patch uploaded by coreyfarrell (license 5909)
    main-utils-12up.patch uploaded by coreyfarrell (license 5909)

Modified:
    branches/1.8/main/utils.c

Modified: branches/1.8/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/utils.c?view=diff&rev=401829&r1=401828&r2=401829
==============================================================================
--- branches/1.8/main/utils.c (original)
+++ branches/1.8/main/utils.c Thu Oct 24 15:32:37 2013
@@ -1007,9 +1007,6 @@
 	struct thr_lock_info *lock_info;
 	struct ast_str *str;
 
-	if (!(str = ast_str_create(4096)))
-		return CLI_FAILURE;
-
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "core show locks";
@@ -1022,6 +1019,9 @@
 	case CLI_GENERATE:
 		return NULL;
 	}
+
+	if (!(str = ast_str_create(4096)))
+		return CLI_FAILURE;
 
 	ast_str_append(&str, 0, "\n" 
 	               "=======================================================================\n"
@@ -2116,6 +2116,13 @@
 	return 0;
 }
 
+#if defined(DEBUG_THREADS) && !defined(LOW_MEMORY)
+static void utils_shutdown(void)
+{
+	ast_cli_unregister_multiple(utils_cli, ARRAY_LEN(utils_cli));
+}
+#endif
+
 int ast_utils_init(void)
 {
 #ifdef HAVE_DEV_URANDOM
@@ -2125,6 +2132,7 @@
 #ifdef DEBUG_THREADS
 #if !defined(LOW_MEMORY)
 	ast_cli_register_multiple(utils_cli, ARRAY_LEN(utils_cli));
+	ast_register_atexit(utils_shutdown);
 #endif
 #endif
 	return 0;




More information about the asterisk-commits mailing list