epoll: close fd on alloc fail at initialization

If the memory allocations fail then we free any other allocated
structures but don't close the file descriptor resulting in an leak of
fd's.
This commit is contained in:
Jamie Iles 2011-10-26 13:24:30 +01:00 committed by Nick Mathewson
parent 3c824bd334
commit 1aee718362

View File

@ -120,8 +120,10 @@ epoll_init(struct event_base *base)
evutil_make_socket_closeonexec(epfd); evutil_make_socket_closeonexec(epfd);
if (!(epollop = mm_calloc(1, sizeof(struct epollop)))) if (!(epollop = mm_calloc(1, sizeof(struct epollop)))) {
close(epfd);
return (NULL); return (NULL);
}
epollop->epfd = epfd; epollop->epfd = epfd;
@ -129,6 +131,7 @@ epoll_init(struct event_base *base)
epollop->events = mm_calloc(INITIAL_NEVENT, sizeof(struct epoll_event)); epollop->events = mm_calloc(INITIAL_NEVENT, sizeof(struct epoll_event));
if (epollop->events == NULL) { if (epollop->events == NULL) {
mm_free(epollop); mm_free(epollop);
close(epfd);
return (NULL); return (NULL);
} }
epollop->nevents = INITIAL_NEVENT; epollop->nevents = INITIAL_NEVENT;