[asterisk-commits] rizzo: branch 1.4 r46117 - /branches/1.4/main/http.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Oct 24 01:34:24 MST 2006


Author: rizzo
Date: Tue Oct 24 03:34:23 2006
New Revision: 46117

URL: http://svn.digium.com/view/asterisk?rev=46117&view=rev
Log:
merge 45152   don't leak descriptors in http.c


Modified:
    branches/1.4/main/http.c

Modified: branches/1.4/main/http.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/http.c?rev=46117&r1=46116&r2=46117&view=diff
==============================================================================
--- branches/1.4/main/http.c (original)
+++ branches/1.4/main/http.c Tue Oct 24 03:34:23 2006
@@ -494,6 +494,8 @@
 	pthread_attr_t attr;
 	
 	for (;;) {
+		int flags;
+
 		ast_wait_for_input(httpfd, -1);
 		sinlen = sizeof(sin);
 		fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);
@@ -503,25 +505,28 @@
 			continue;
 		}
 		ser = ast_calloc(1, sizeof(*ser));
-		if (ser) {
-			int flags = fcntl(fd, F_GETFL);
-			fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
-			ser->fd = fd;
-			memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
-			if ((ser->f = fdopen(ser->fd, "w+"))) {
-				pthread_attr_init(&attr);
-				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-				
-				if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
-					ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
-					fclose(ser->f);
-					free(ser);
-				}
-			} else {
-				ast_log(LOG_WARNING, "fdopen failed!\n");
-				close(ser->fd);
+		if (!ser) {
+			ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
+			close(fd);
+			continue;
+		}
+		flags = fcntl(fd, F_GETFL);
+		fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
+		ser->fd = fd;
+		memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
+		if ((ser->f = fdopen(ser->fd, "w+"))) {
+			pthread_attr_init(&attr);
+			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+			
+			if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
+				ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
+				fclose(ser->f);
 				free(ser);
 			}
+		} else {
+			ast_log(LOG_WARNING, "fdopen failed!\n");
+			close(ser->fd);
+			free(ser);
 		}
 	}
 	return NULL;



More information about the asterisk-commits mailing list