mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@45152 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
39
main/http.c
39
main/http.c
@@ -494,6 +494,8 @@ static void *http_root(void *data)
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
int flags;
|
||||||
|
|
||||||
ast_wait_for_input(httpfd, -1);
|
ast_wait_for_input(httpfd, -1);
|
||||||
sinlen = sizeof(sin);
|
sinlen = sizeof(sin);
|
||||||
fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);
|
fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);
|
||||||
@@ -503,25 +505,28 @@ static void *http_root(void *data)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ser = ast_calloc(1, sizeof(*ser));
|
ser = ast_calloc(1, sizeof(*ser));
|
||||||
if (ser) {
|
if (!ser) {
|
||||||
int flags = fcntl(fd, F_GETFL);
|
ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
|
||||||
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
close(fd);
|
||||||
ser->fd = fd;
|
continue;
|
||||||
memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
|
}
|
||||||
if ((ser->f = fdopen(ser->fd, "w+"))) {
|
flags = fcntl(fd, F_GETFL);
|
||||||
pthread_attr_init(&attr);
|
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
ser->fd = fd;
|
||||||
|
memcpy(&ser->requestor, &sin, sizeof(ser->requestor));
|
||||||
if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
|
if ((ser->f = fdopen(ser->fd, "w+"))) {
|
||||||
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
pthread_attr_init(&attr);
|
||||||
fclose(ser->f);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
free(ser);
|
|
||||||
}
|
if (ast_pthread_create_background(&launched, &attr, ast_httpd_helper_thread, ser)) {
|
||||||
} else {
|
ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
|
||||||
ast_log(LOG_WARNING, "fdopen failed!\n");
|
fclose(ser->f);
|
||||||
close(ser->fd);
|
|
||||||
free(ser);
|
free(ser);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_WARNING, "fdopen failed!\n");
|
||||||
|
close(ser->fd);
|
||||||
|
free(ser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user