summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
authorJonathan Rose <jrose@digium.com>2013-10-24 20:34:53 +0000
committerJonathan Rose <jrose@digium.com>2013-10-24 20:34:53 +0000
commit6fb07febbc43c1c4cbcef596a908b684b9bf95a6 (patch)
tree1eb5aec1f6471ce8a170ad7c273a902433a310e9 /main/utils.c
parent1d0a6d2b2c9740d29d6598414bc4a5cbb17a4d23 (diff)
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) ........ Merged revisions 401829 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 401830 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 401831 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@401832 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/main/utils.c b/main/utils.c
index 6eebff71a..8252488a9 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2277,6 +2277,15 @@ int ast_safe_mkdir(const char *base_path, const char *path, int mode)
return safe_mkdir(absolute_base_path, p, mode);
}
+static void utils_shutdown(void)
+{
+ close(dev_urandom_fd);
+ dev_urandom_fd = -1;
+#if defined(DEBUG_THREADS) && !defined(LOW_MEMORY)
+ ast_cli_unregister_multiple(utils_cli, ARRAY_LEN(utils_cli));
+#endif
+}
+
int ast_utils_init(void)
{
dev_urandom_fd = open("/dev/urandom", O_RDONLY);
@@ -2286,6 +2295,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;
}