From 1aee718362f8bc88369d750bdb87b4f8af48af28 Mon Sep 17 00:00:00 2001 From: Jamie Iles Date: Wed, 26 Oct 2011 13:24:30 +0100 Subject: [PATCH] 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. --- epoll.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/epoll.c b/epoll.c index b08d78f8f4..b5dd1309a4 100644 --- a/epoll.c +++ b/epoll.c @@ -120,8 +120,10 @@ 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; @@ -129,6 +131,7 @@ epoll_init(struct event_base *base) 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;