diff --git a/http.c b/http.c index b9714d33..00a3499b 100644 --- a/http.c +++ b/http.c @@ -3825,9 +3825,12 @@ bind_socket_ai(struct evutil_addrinfo *ai, int reuse) if (evutil_make_socket_closeonexec(fd) < 0) goto out; - setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); - if (reuse) - evutil_make_listen_socket_reuseable(fd); + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on))<0) + goto out; + if (reuse) { + if (evutil_make_listen_socket_reuseable(fd) < 0) + goto out; + } if (ai != NULL) { r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen); diff --git a/listener.c b/listener.c index 9941e1d8..a78ca0d6 100644 --- a/listener.c +++ b/listener.c @@ -226,9 +226,15 @@ evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb, } } - setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on)); + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0) { + evutil_closesocket(fd); + return NULL; + } if (flags & LEV_OPT_REUSEABLE) { - evutil_make_listen_socket_reuseable(fd); + if (evutil_make_listen_socket_reuseable(fd) < 0) { + evutil_closesocket(fd); + return NULL; + } } if (sa) {