aboutsummaryrefslogtreecommitdiffstats
path: root/main/http.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-15 20:54:15 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-15 20:54:15 +0000
commit8b4ea6655612f64276672c0a2cdc5a636482a38d (patch)
tree5c7760b650c87df326274ff9b1262cc0185e4a4b /main/http.c
parent454cf4267d5774704956e2828ab55d145edbe844 (diff)
don't forget to close a descriptor on a malloc failure.
On passing, small rearrangement of the code to reduce indentation. There is a bit more cleanup planned for this file, so a merge to 1.4 will be done when it is all done. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@45152 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/http.c')
-rw-r--r--main/http.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/main/http.c b/main/http.c
index 054e859aa..26a443853 100644
--- a/main/http.c
+++ b/main/http.c
@@ -494,6 +494,8 @@ static void *http_root(void *data)
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 @@ static void *http_root(void *data)
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;