]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
utils: Fix memory leaks and missed unregistration of CLI commands on shutdown
authorJonathan Rose <jrose@digium.com>
Thu, 24 Oct 2013 20:33:37 +0000 (20:33 +0000)
committerJonathan Rose <jrose@digium.com>
Thu, 24 Oct 2013 20:33:37 +0000 (20:33 +0000)
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)
........

Merged revisions 401829 from http://svn.asterisk.org/svn/asterisk/branches/1.8

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@401830 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/utils.c

index 083fb9433b4a75b3c152baa37598349afe73beb2..85f78a36b27225b9b5de1b5d6b2cc7447b3549c4 100644 (file)
@@ -1025,9 +1025,6 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_
        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";
@@ -1041,7 +1038,10 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_
                return NULL;
        }
 
-       ast_str_append(&str, 0, "\n"
+       if (!(str = ast_str_create(4096)))
+               return CLI_FAILURE;
+
+       ast_str_append(&str, 0, "\n" 
                       "=======================================================================\n"
                       "=== %s\n"
                       "=== Currently Held Locks\n"
@@ -2163,6 +2163,17 @@ int ast_mkdir(const char *path, int mode)
        return 0;
 }
 
+static void utils_shutdown(void)
+{
+#ifdef HAVE_DEV_URANDOM
+       close(dev_urandom_fd);
+       dev_urandom_fd = -1;
+#endif
+#if defined(DEBUG_THREADS) && !defined(LOW_MEMORY)
+       ast_cli_unregister_multiple(utils_cli, ARRAY_LEN(utils_cli));
+#endif
+}
+
 int ast_utils_init(void)
 {
 #ifdef HAVE_DEV_URANDOM
@@ -2174,6 +2185,7 @@ int ast_utils_init(void)
        ast_cli_register_multiple(utils_cli, ARRAY_LEN(utils_cli));
 #endif
 #endif
+       ast_register_atexit(utils_shutdown);
        return 0;
 }