[asterisk-commits] russell: branch 1.4 r81997 - /branches/1.4/main/asterisk.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 8 13:41:32 CDT 2007


Author: russell
Date: Sat Sep  8 13:41:32 2007
New Revision: 81997

URL: http://svn.digium.com/view/asterisk?view=rev&rev=81997
Log:
Fix a small memory leak.  ast_unregister_atexit() did not free the entry it removed.

Modified:
    branches/1.4/main/asterisk.c

Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=81997&r1=81996&r2=81997
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Sat Sep  8 13:41:32 2007
@@ -699,22 +699,26 @@
 
 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 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END
 	AST_LIST_UNLOCK(&atexits);
+
+	if (ae)
+		free(ae);
 }
 
 static int fdprint(int fd, const char *s)




More information about the asterisk-commits mailing list