]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix a small memory leak. ast_unregister_atexit() did not free the entry it removed.
authorRussell Bryant <russell@russellbryant.com>
Sat, 8 Sep 2007 18:41:32 +0000 (18:41 +0000)
committerRussell Bryant <russell@russellbryant.com>
Sat, 8 Sep 2007 18:41:32 +0000 (18:41 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@81997 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/asterisk.c

index df4b55b72758391186410baddc646eccefb1da5e..19d4237f307a4199cd019ba3d3fa924fc62a2ba5 100644 (file)
@@ -699,22 +699,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_LIST_LOCK(&atexits);
-       if ((ae = ast_calloc(1, sizeof(*ae)))) {
-               AST_LIST_INSERT_HEAD(&atexits, ae, list);
-               ae->func = func;
-               res = 0;
-       }
+       AST_LIST_INSERT_HEAD(&atexits, ae, list);
        AST_LIST_UNLOCK(&atexits);
-       return res;
+
+       return 0;
 }
 
 void ast_unregister_atexit(void (*func)(void))
 {
-       struct ast_atexit *ae;
+       struct ast_atexit *ae = NULL;
+
        AST_LIST_LOCK(&atexits);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
                if (ae->func == func) {
@@ -724,6 +728,9 @@ void ast_unregister_atexit(void (*func)(void))
        }
        AST_LIST_TRAVERSE_SAFE_END
        AST_LIST_UNLOCK(&atexits);
+
+       if (ae)
+               free(ae);
 }
 
 static int fdprint(int fd, const char *s)