Skip to content

Commit

Permalink
epoll: close fd on alloc fail at initialization
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jamie Iles authored and nmathewson committed Oct 26, 2011
1 parent 3c824bd commit 1aee718
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ epoll_init(struct event_base *base)

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);
}

epollop->epfd = epfd;

/* Initialize fields */
epollop->events = mm_calloc(INITIAL_NEVENT, sizeof(struct epoll_event));
if (epollop->events == NULL) {
mm_free(epollop);
close(epfd);
return (NULL);
}
epollop->nevents = INITIAL_NEVENT;
Expand Down

0 comments on commit 1aee718

Please sign in to comment.