aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-08 18:45:51 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-09-08 18:45:51 +0000
commit5b21321d3e6851ec430389ac1b7da636e82077c1 (patch)
treeae05229e335e82ddb5e5c4393cf4800e5bb26145 /main/asterisk.c
parent300d5944b6558fcd7377a4cf84884bddf62691a5 (diff)
Merged revisions 81997 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r81997 | russell | 2007-09-08 13:41:32 -0500 (Sat, 08 Sep 2007) | 2 lines Fix a small memory leak. ast_unregister_atexit() did not free the entry it removed. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@81998 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 86d300e35..d6ef560d6 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -671,22 +671,26 @@ static char *complete_show_version_files(const char *line, const char *word, int
int ast_register_atexit(void (*func)(void))
{
- int res = -1;
struct ast_atexit *ae;
+
+ if (!(ae = ast_calloc(1, sizeof(*ae))))
+ return -1;
+
+ ae->func = func;
+
ast_unregister_atexit(func);
+
AST_RWLIST_WRLOCK(&atexits);
- if ((ae = ast_calloc(1, sizeof(*ae)))) {
- AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
- ae->func = func;
- res = 0;
- }
+ AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
AST_RWLIST_UNLOCK(&atexits);
- return res;
+
+ return 0;
}
void ast_unregister_atexit(void (*func)(void))
{
- struct ast_atexit *ae;
+ struct ast_atexit *ae = NULL;
+
AST_RWLIST_WRLOCK(&atexits);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
if (ae->func == func) {
@@ -696,6 +700,9 @@ void ast_unregister_atexit(void (*func)(void))
}
AST_RWLIST_TRAVERSE_SAFE_END
AST_RWLIST_UNLOCK(&atexits);
+
+ if (ae)
+ free(ae);
}
static int fdprint(int fd, const char *s)