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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 18 15:56:44 CDT 2007


Author: russell
Date: Tue Sep 18 15:56:43 2007
New Revision: 82867

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82867
Log:
Fix a memory leak that can occur on systems under higher load.  The issue is
that when events are appended to the master event queue, they use the number
of active sessions as a use count so it will know when all active sessions
at the time the event happened have consumed it.  However, the handling of
the number of sessions was not properly synchronized, so the use count was
not always correct, causing an event to disappear early, or get stuck in
the event queue for forever.

(closes issue #9238, reported by bweschke, patch from Ivan, modified by me)

Modified:
    branches/1.4/main/manager.c

Modified: branches/1.4/main/manager.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/manager.c?view=diff&rev=82867&r1=82866&r2=82867
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Tue Sep 18 15:56:43 2007
@@ -683,9 +683,9 @@
 {
 	AST_LIST_LOCK(&sessions);
 	AST_LIST_REMOVE(&sessions, s, list);
+	num_sessions--;
 	AST_LIST_UNLOCK(&sessions);
 
-	ast_atomic_fetchadd_int(&num_sessions, -1);
 	free_session(s);
 }
 
@@ -2235,6 +2235,7 @@
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&sessions, s, list) {
 			if (s->sessiontimeout && (now > s->sessiontimeout) && !s->inuse) {
 				AST_LIST_REMOVE_CURRENT(&sessions, list);
+				num_sessions--;
 				if (s->authenticated && (option_verbose > 1) && displayconnects) {
 					ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' timed out from %s\n",
 						s->username, ast_inet_ntoa(s->sin.sin_addr));
@@ -2253,8 +2254,6 @@
 			free(eqe);
 		}
 		AST_LIST_UNLOCK(&sessions);
-		if (s)
-			ast_atomic_fetchadd_int(&num_sessions, -1);
 
 		sinlen = sizeof(sin);
 		pfds[0].fd = asock;
@@ -2277,8 +2276,6 @@
 		if (!(s = ast_calloc(1, sizeof(*s))))
 			continue;
 
-		ast_atomic_fetchadd_int(&num_sessions, 1);
-		
 		memcpy(&s->sin, &sin, sizeof(sin));
 		s->writetimeout = 100;
 		s->waiting_thread = AST_PTHREADT_NULL;
@@ -2296,13 +2293,14 @@
 		s->send_events = -1;
 		AST_LIST_LOCK(&sessions);
 		AST_LIST_INSERT_HEAD(&sessions, s, list);
+		num_sessions++;
 		/* Find the last place in the master event queue and hook ourselves
 		   in there */
 		s->eventq = master_eventq;
 		while(s->eventq->next)
 			s->eventq = s->eventq->next;
+		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
 		AST_LIST_UNLOCK(&sessions);
-		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
 		if (ast_pthread_create_background(&s->t, &attr, session_do, s))
 			destroy_session(s);
 	}
@@ -2580,9 +2578,9 @@
 		s->eventq = master_eventq;
 		while (s->eventq->next)
 			s->eventq = s->eventq->next;
-		AST_LIST_UNLOCK(&sessions);
 		ast_atomic_fetchadd_int(&s->eventq->usecount, 1);
 		ast_atomic_fetchadd_int(&num_sessions, 1);
+		AST_LIST_UNLOCK(&sessions);
 	}
 
 	/* Reset HTTP timeout.  If we're not yet authenticated, keep it extremely short */




More information about the asterisk-commits mailing list